// 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";
import "google/rpc/status.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 = "BindingMatchingResourceProto";
option java_package = "com.google.cloud.backupdr.v1beta";
option php_namespace = "Google\\Cloud\\BackupDR\\V1beta";
option ruby_package = "Google::Cloud::BackupDR::V1beta";

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

// Request message for List BindingMatchingResources.
message ListBindingMatchingResourcesRequest {
  // Required. The project, location, auto protection policy and binding for
  // which to retrieve `BindingMatchingResources` information. Format:
  // `projects/{project}/locations/{location}/autoProtectionPolicies/{auto_protection_policy}/bindings/{binding}`.
  // In Google Cloud Backup and DR, locations map to Google Cloud regions, for
  // example **us-central1**.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "backupdr.googleapis.com/BindingMatchingResource"
    }
  ];

  // Optional. The maximum number of `BindingMatchingResources` to return in a
  // single response. The default page size is 100 and maximum page size is 200.
  // Note that the response may include a partial list and a caller should
  // only rely on the response's
  // [next_page_token][google.cloud.backupdr.v1beta.ListBindingMatchingResourcesResponse.next_page_token]
  // to determine if there are more instances left to be queried.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. The value of
  // [next_page_token][google.cloud.backupdr.v1beta.ListBindingMatchingResourcesResponse.next_page_token]
  // received from a previous `ListBindingMatchingResources` call. Provide this
  // to retrieve the subsequent page in a multi-page list of results. When
  // paginating, all other parameters provided to `ListBindingMatchingResources`
  // must match the call that provided the page token.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Field match expression used to filter the results.
  string filter = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Field by which to sort the results.
  string order_by = 5 [(google.api.field_behavior) = OPTIONAL];
}

// The response message for getting a list of `BindingMatchingResources`.
message ListBindingMatchingResourcesResponse {
  // The list of `BindingMatchingResources` in the project,location for the
  // specified binding.
  repeated BindingMatchingResource matching_resources = 1;

  // A token which may be sent as
  // [page_token][google.cloud.backupdr.v1beta.ListBindingMatchingResourcesRequest.page_token]
  // in a subsequent `ListBindingMatchingResources` call to retrieve the next
  // page of results. If this field is omitted or empty, then there are no more
  // results to return.
  string next_page_token = 2;
}

// BindingMatchingResource contains the details of a resource that matches the
// criteria of a binding.
message BindingMatchingResource {
  option (google.api.resource) = {
    type: "backupdr.googleapis.com/BindingMatchingResource"
    pattern: "projects/{project}/locations/{location}/autoProtectionPolicies/{auto_protection_policy}/bindings/{binding}/matchingResources/{matching_resource}"
    plural: "bindingMatchingResources"
    singular: "bindingMatchingResource"
  };

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

  // Required. Immutable. Resource name of the workload that matches the
  // criteria of the binding.
  //
  // The format can be either a relative resource name (e.g.,
  // `projects/my-project/zones/us-central1-a/instances/my-instance`) or a
  // schemeless full resource name (e.g.,
  // `//compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-instance`).
  string resource = 2 [
    (google.api.field_behavior) = IMMUTABLE,
    (google.api.field_behavior) = REQUIRED
  ];

  // Output only. The timestamp when the resource was last evaluated for
  // protection.
  google.protobuf.Timestamp last_evaluation_time = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The auto protection details of the resource from the current
  // binding's perspective.
  AutoProtectionDetails auto_protection_details = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// AutoProtectionDetails contains the protection details of a resource from the
// current binding's perspective.
message AutoProtectionDetails {
  // Enum for protection state of the resource.
  enum State {
    // State unspecified.
    STATE_UNSPECIFIED = 0;

    // Resource is protected.
    PROTECTED = 1;

    // Resource protection failed.
    PROTECTION_FAILED = 2;

    // Resource is being unprotected.
    UNPROTECTING = 3;

    // Resource unprotection failed.
    UNPROTECTION_FAILED = 4;
  }

  // Output only. Protection state of the resource from the current binding's
  // perspective. Output only.
  State state = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Resource name of backup plan association linked to the
  // resource, if any. Format:
  // projects/{project}/locations/{location}/backupPlanAssociations/{backupPlanAssociationId}
  string backup_plan_association = 2 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/BackupPlanAssociation"
    }
  ];

  // Output only. Resource name of the datasource linked to the resource, if
  // any. Format:
  // projects/{project}/locations/{location}/backupVaults/{backupVaultId}/dataSources/{dataSourceId}
  string data_source = 3 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/DataSource"
    }
  ];

  // Output only. Error during last sync for protection/unprotection, if any.
  google.rpc.Status error = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
}
