// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.cloud.backupdr.v1beta;

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Cloud.BackupDR.V1Beta";
option go_package = "cloud.google.com/go/backupdr/apiv1beta/backupdrpb;backupdrpb";
option java_multiple_files = true;
option java_outer_classname = "AutoProtectionPolicyBindingProto";
option java_package = "com.google.cloud.backupdr.v1beta";
option php_namespace = "Google\\Cloud\\BackupDR\\V1beta";
option ruby_package = "Google::Cloud::BackupDR::V1beta";

// An AutoprotectionPolicyBinding (APPA) acts as the bridge between an
// AutoprotectionPolicy and the scope (Project, Folder, or Organization) where
// the policy should be applied.
message AutoProtectionPolicyBinding {
  option (google.api.resource) = {
    type: "backupdr.googleapis.com/AutoProtectionPolicyBinding"
    pattern: "projects/{project}/locations/{location}/autoProtectionPolicies/{auto_protection_policy}/bindings/{binding}"
    plural: "autoProtectionPolicyBindings"
    singular: "autoProtectionPolicyBinding"
  };

  // The state of an AutoProtectionPolicyBinding.
  enum State {
    // The state of the binding is unspecified.
    STATE_UNSPECIFIED = 0;

    // The binding is being created.
    CREATING = 1;

    // The binding is active.
    ACTIVE = 2;

    // The binding deletion is initiated.
    DELETION_INITIATED = 3;
  }

  // Identifier. The resource name of the AutoProtectionPolicyBinding.
  // Format:
  // `projects/{project}/locations/{location}/autoProtectionPolicies/{auto_protection_policy}/bindings/{binding}`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Optional. A description of the binding.
  string description = 2 [(google.api.field_behavior) = OPTIONAL];

  // Output only. The current state of the AutoProtectionPolicyBinding.
  State state = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Required. Immutable. Resource Id of target container on which policy will
  // be applied. Format: projects/{project_id}
  string scope = 4 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.field_behavior) = IMMUTABLE,
    (google.api.resource_reference) = { type: "*" }
  ];

  // Output only. Summaries of the last policy application when the job has run,
  // with one entry per resource type specified in the AutoProtectionPolicy.
  BindingEvaluationSummary binding_evaluation_summary = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The timestamp when the binding was created.
  google.protobuf.Timestamp create_time = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The timestamp when the binding was last updated.
  google.protobuf.Timestamp update_time = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. Output only. The etag for the binding.
  // If this is provided on update, it must match the server's etag.
  string etag = 8 [(google.api.field_behavior) = OPTIONAL];
}

// BindingEvaluationSummary contains the summary of the last run of job
// that applies policy to matching resources for a given binding.
message BindingEvaluationSummary {
  // Output only. The number of resources that currently match the policy's
  // criteria.
  int64 matching_resource_count = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The number of matching resources that are successfully
  // protected.
  int64 protected_resource_count = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The number of matching resources whose protection failed
  // during job run.
  int64 failed_resource_count = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Request message for creating an AutoProtectionPolicyBinding.
message CreateAutoProtectionPolicyBindingRequest {
  // Required. The parent resource where this binding will be created.
  // Format:
  // projects/{project}/locations/{location}/autoProtectionPolicies/{auto_protection_policy}
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/AutoProtectionPolicy"
    }
  ];

  // Required. The ID to use for the binding.
  // This will become the final component of the binding's resource name.
  string auto_protection_policy_binding_id = 2
      [(google.api.field_behavior) = REQUIRED];

  // Required. The AutoProtectionPolicyBinding resource to create.
  AutoProtectionPolicyBinding auto_protection_policy_binding = 3
      [(google.api.field_behavior) = REQUIRED];
}

// Request message for getting an AutoProtectionPolicyBinding.
message GetAutoProtectionPolicyBindingRequest {
  // Required. The name of the binding to retrieve.
  // Format:
  // projects/{project}/locations/{location}/autoProtectionPolicies/{auto_protection_policy}/bindings/{binding}
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/AutoProtectionPolicyBinding"
    }
  ];
}

// Request message for ListAutoProtectionPolicyBindings.
message ListAutoProtectionPolicyBindingsRequest {
  // Required. The project and location for which to retrieve the list of
  // policies. Format: projects/{project}/locations/{location}
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/AutoProtectionPolicy"
    }
  ];

  // Optional. The maximum number of policies to return in a single page.
  // If unspecified, a server-default value will be used.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous
  // `ListAutoProtectionPolicies` call. Provide this to retrieve the subsequent
  // page.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A filter expression that filters resources listed in the
  // response. The following fields are filterable:
  string filter = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. An expression that sorts the results in the response. The
  // following fields are sortable:
  string order_by = 5 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for ListAutoProtectionPolicyBindings.
message ListAutoProtectionPolicyBindingsResponse {
  // A list of the AutoProtectionPolicyBindings resources found.
  repeated AutoProtectionPolicyBinding auto_protection_policy_bindings = 1;

  // A token that can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;

  // Unordered list. Locations that could not be reached.
  repeated string unreachable = 3
      [(google.api.field_behavior) = UNORDERED_LIST];
}

// Request message for initiating delete of an AutoProtectionPolicyBinding.
message InitiateDeleteAutoProtectionPolicyBindingRequest {
  // Required. The name of the binding to delete.
  // Format:
  // projects/{project}/locations/{location}/autoProtectionPolicies/{auto_protection_policy}/bindings/{binding}
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/AutoProtectionPolicyBinding"
    }
  ];
}
