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

// AppliedAutoProtectionPolicy is a read-only view of AutoProtectionPolicy
// and AutoProtectionPolicyBinding resources that apply to a given workload
// project.
message AppliedAutoProtectionPolicy {
  option (google.api.resource) = {
    type: "backupdr.googleapis.com/AppliedAutoProtectionPolicy"
    pattern: "projects/{project}/locations/{location}/appliedAutoProtectionPolicies/{applied_auto_protection_policy}"
    plural: "appliedAutoProtectionPolicies"
    singular: "appliedAutoProtectionPolicy"
  };

  // Represents the various states an applied auto protection policy can be in.
  enum State {
    // State is not specified.
    STATE_UNSPECIFIED = 0;

    // The policy is in the process of being applied.
    CREATING = 1;

    // The policy has been applied and is active.
    ACTIVE = 2;

    // The policy is in the process of being removed.
    DELETION_INITIATED = 3;
  }

  // Identifier. Canonical resource name.
  // Format:
  // projects/{workload-project-number}/locations/{location}/appliedAutoProtectionPolicies/{id}.
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Output only. The full resource name of the AutoProtectionPolicyBinding that
  // applies the source policy to a scope including this workload project. e.g.,
  // projects/{admin-project}/locations/{location}/autoProtectionPolicies/{policy_id}/autoProtectionPolicyBindings/{binding_id}.
  string source_binding = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The criteria resources must meet for this rule to apply. From
  // AutoProtectionPolicy.criteria.
  Criteria criteria = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The set of backup plan configurations, mirroring the
  // backup_plan_details from the source AutoProtectionPolicy. Each element
  // specifies a backup plan for a given resource type.
  repeated BackupPlanDetail backup_plan_details = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp indicating when the binding was last modified.
  google.protobuf.Timestamp update_time = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

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

  // Output only. The summary of the last policy application when the job has
  // run.
  BindingEvaluationSummary binding_evaluation_summary = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The status of the applied auto protection policy.
  State status = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
}

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

  // Optional. The maximum number of applied policies to return in a single
  // page.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous
  // `ListAppliedAutoProtectionPolicies` call.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];

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

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

// Response message for ListAppliedAutoProtectionPolicies.
message ListAppliedAutoProtectionPoliciesResponse {
  // A list of the AppliedAutoProtectionPolicy resources found.
  repeated AppliedAutoProtectionPolicy applied_auto_protection_policies = 1;

  // A token that can be sent as `page_token` to retrieve the next page.
  string next_page_token = 2;

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