// Copyright 2025 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.v1;

import "google/api/field_behavior.proto";
import "google/api/field_info.proto";
import "google/api/resource.proto";
import "google/cloud/backupdr/v1/backupvault_alloydb.proto";
import "google/cloud/backupdr/v1/backupvault_cloudsql.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
import "google/rpc/status.proto";

option csharp_namespace = "Google.Cloud.BackupDR.V1";
option go_package = "cloud.google.com/go/backupdr/apiv1/backupdrpb;backupdrpb";
option java_multiple_files = true;
option java_outer_classname = "BackupPlanAssociationProto";
option java_package = "com.google.cloud.backupdr.v1";
option php_namespace = "Google\\Cloud\\BackupDR\\V1";
option ruby_package = "Google::Cloud::BackupDR::V1";

// A BackupPlanAssociation represents a single BackupPlanAssociation which
// contains details like workload, backup plan etc
message BackupPlanAssociation {
  option (google.api.resource) = {
    type: "backupdr.googleapis.com/BackupPlanAssociation"
    pattern: "projects/{project}/locations/{location}/backupPlanAssociations/{backup_plan_association}"
    plural: "backupPlanAssociations"
    singular: "backupPlanAssociation"
  };

  // Enum for State of BackupPlan Association
  enum State {
    // State not set.
    STATE_UNSPECIFIED = 0;

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

    // The resource has been created and is fully usable.
    ACTIVE = 2;

    // The resource is being deleted.
    DELETING = 3;

    // The resource has been created but is not usable.
    INACTIVE = 4;

    // The resource is being updated.
    UPDATING = 5;
  }

  // Output only. Identifier. The resource name of BackupPlanAssociation in
  // below format Format :
  // projects/{project}/locations/{location}/backupPlanAssociations/{backupPlanAssociationId}
  string name = 1 [
    (google.api.field_behavior) = IDENTIFIER,
    (google.api.field_behavior) = OUTPUT_ONLY
  ];

  // Required. Immutable. Resource type of workload on which backupplan is
  // applied
  string resource_type = 2 [
    (google.api.field_behavior) = IMMUTABLE,
    (google.api.field_behavior) = REQUIRED
  ];

  // Required. Immutable. Resource name of workload on which the backup plan is
  // applied.
  //
  // The format can either be the resource name (e.g.,
  // "projects/my-project/zones/us-central1-a/instances/my-instance") or the
  // full resource URI (e.g.,
  // "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/my-instance").
  string resource = 3 [
    (google.api.field_behavior) = IMMUTABLE,
    (google.api.field_behavior) = REQUIRED
  ];

  // Required. Resource name of backup plan which needs to be applied on
  // workload. Format:
  // projects/{project}/locations/{location}/backupPlans/{backupPlanId}
  string backup_plan = 4 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/BackupPlan"
    }
  ];

  // Output only. The time when the instance was created.
  google.protobuf.Timestamp create_time = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The time when the instance was updated.
  google.protobuf.Timestamp update_time = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The BackupPlanAssociation resource state.
  State state = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The config info related to backup rules.
  repeated RuleConfigInfo rules_config_info = 8
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Resource name of data source which will be used as storage
  // location for backups taken. Format :
  // projects/{project}/locations/{location}/backupVaults/{backupvault}/dataSources/{datasource}
  string data_source = 9 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Properties of the protected GCP resource.
  oneof resource_properties {
    // Output only. Cloud SQL instance's backup plan association properties.
    CloudSqlInstanceBackupPlanAssociationProperties
        cloud_sql_instance_backup_plan_association_properties = 10
        [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. AlloyDB cluster's backup plan association properties.
    AlloyDBClusterBackupPlanAssociationProperties
        alloydb_cluster_backup_plan_association_properties = 15
        [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Output only. The user friendly revision ID of the `BackupPlanRevision`.
  //
  // Example: v0, v1, v2, etc.
  string backup_plan_revision_id = 11
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The resource id of the `BackupPlanRevision`.
  //
  // Format:
  // `projects/{project}/locations/{location}/backupPlans/{backup_plan}/revisions/{revision_id}`
  string backup_plan_revision_name = 12
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Message for rules config info.
message RuleConfigInfo {
  // Enum for LastBackupState
  enum LastBackupState {
    // State not set.
    LAST_BACKUP_STATE_UNSPECIFIED = 0;

    // The first backup is pending.
    FIRST_BACKUP_PENDING = 1;

    // The most recent backup could not be run/failed because of the lack of
    // permissions.
    PERMISSION_DENIED = 2;

    // The last backup operation succeeded.
    SUCCEEDED = 3;

    // The last backup operation failed.
    FAILED = 4;
  }

  // Output only. Backup Rule id fetched from backup plan.
  string rule_id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The last backup state for rule.
  LastBackupState last_backup_state = 3
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. google.rpc.Status object to store the last backup error.
  google.rpc.Status last_backup_error = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The point in time when the last successful backup was captured
  // from the source.
  google.protobuf.Timestamp last_successful_backup_consistency_time = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Request message for creating a backup plan.
message CreateBackupPlanAssociationRequest {
  // Required. The backup plan association project and location in the format
  // `projects/{project_id}/locations/{location}`. In Cloud BackupDR locations
  // map to GCP regions, for example **us-central1**.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "backupdr.googleapis.com/BackupPlanAssociation"
    }
  ];

  // Required. The name of the backup plan association to create. The name must
  // be unique for the specified project and location.
  string backup_plan_association_id = 2
      [(google.api.field_behavior) = REQUIRED];

  // Required. The resource being created
  BackupPlanAssociation backup_plan_association = 3
      [(google.api.field_behavior) = REQUIRED];

  // Optional. An optional request ID to identify requests. Specify a unique
  // request ID so that if you must retry your request, the server will know to
  // ignore the request if it has already been completed. The server will
  // guarantee that for at least 60 minutes since the first request.
  //
  // For example, consider a situation where you make an initial request and t
  // he request times out. If you make the request again with the same request
  // ID, the server can check if original operation with the same request ID
  // was received, and if so, will ignore the second request. This prevents
  // clients from accidentally creating duplicate commitments.
  //
  // The request ID must be a valid UUID with the exception that zero UUID is
  // not supported (00000000-0000-0000-0000-000000000000).
  string request_id = 4 [
    (google.api.field_info).format = UUID4,
    (google.api.field_behavior) = OPTIONAL
  ];
}

// Request message for List BackupPlanAssociation
message ListBackupPlanAssociationsRequest {
  // Required. The project and location for which to retrieve backup Plan
  // Associations information, in the format
  // `projects/{project_id}/locations/{location}`. In Cloud BackupDR, locations
  // map to GCP regions, for example **us-central1**. To retrieve backup plan
  // associations for all locations, use "-" for the
  // `{location}` value.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "backupdr.googleapis.com/BackupPlanAssociation"
    }
  ];

  // Optional. Requested page size. Server may return fewer items than
  // requested. If unspecified, server will pick an appropriate default.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A token identifying a page of results the server should return.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Filtering results
  string filter = 4 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for List BackupPlanAssociation
message ListBackupPlanAssociationsResponse {
  // The list of Backup Plan Associations in the project for the specified
  // location.
  //
  // If the `{location}` value in the request is "-", the response contains a
  // list of instances from all locations. In case any location is unreachable,
  // the response will only return backup plan associations in reachable
  // locations and the 'unreachable' field will be populated with a list of
  // unreachable locations.
  repeated BackupPlanAssociation backup_plan_associations = 1;

  // A token identifying a page of results the server should return.
  string next_page_token = 2;

  // Locations that could not be reached.
  repeated string unreachable = 3;
}

// Request for the FetchBackupPlanAssociationsForResourceType method.
message FetchBackupPlanAssociationsForResourceTypeRequest {
  // Required. The parent resource name.
  // Format: projects/{project}/locations/{location}
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "backupdr.googleapis.com/BackupPlanAssociation"
    }
  ];

  // Required. The type of the GCP resource.
  // Ex: sql.googleapis.com/Instance
  string resource_type = 2 [(google.api.field_behavior) = REQUIRED];

  // Optional. The maximum number of BackupPlanAssociations to return. The
  // service may return fewer than this value. If unspecified, at most 50
  // BackupPlanAssociations will be returned. The maximum value is 100; values
  // above 100 will be coerced to 100.
  int32 page_size = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous call of
  // `FetchBackupPlanAssociationsForResourceType`.
  // Provide this to retrieve the subsequent page.
  //
  // When paginating, all other parameters provided to
  // `FetchBackupPlanAssociationsForResourceType` must match
  // the call that provided the page token.
  string page_token = 4 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A filter expression that filters the results fetched in the
  // response. The expression must specify the field name, a comparison
  // operator, and the value that you want to use for filtering. Supported
  // fields:
  // * resource
  // * backup_plan
  // * state
  // * data_source
  // * cloud_sql_instance_backup_plan_association_properties.instance_create_time
  string filter = 5 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A comma-separated list of fields to order by, sorted in ascending
  // order. Use "desc" after a field name for descending.
  //
  // Supported fields:
  // * name
  string order_by = 6 [(google.api.field_behavior) = OPTIONAL];
}

// Response for the FetchBackupPlanAssociationsForResourceType method.
message FetchBackupPlanAssociationsForResourceTypeResponse {
  // Output only. The BackupPlanAssociations from the specified parent.
  repeated BackupPlanAssociation backup_plan_associations = 1
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. A token, which 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 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Request message for getting a BackupPlanAssociation resource.
message GetBackupPlanAssociationRequest {
  // Required. Name of the backup plan association resource, in the format
  // `projects/{project}/locations/{location}/backupPlanAssociations/{backupPlanAssociationId}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/BackupPlanAssociation"
    }
  ];
}

// Request message for deleting a backup plan association.
message DeleteBackupPlanAssociationRequest {
  // Required. Name of the backup plan association resource, in the format
  // `projects/{project}/locations/{location}/backupPlanAssociations/{backupPlanAssociationId}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/BackupPlanAssociation"
    }
  ];

  // Optional. An optional request ID to identify requests. Specify a unique
  // request ID so that if you must retry your request, the server will know to
  // ignore the request if it has already been completed. The server will
  // guarantee that for at least 60 minutes after the first request.
  //
  // For example, consider a situation where you make an initial request and
  // the request times out. If you make the request again with the same request
  // ID, the server can check if original operation with the same request ID
  // was received, and if so, will ignore the second request. This prevents
  // clients from accidentally creating duplicate commitments.
  //
  // The request ID must be a valid UUID with the exception that zero UUID is
  // not supported (00000000-0000-0000-0000-000000000000).
  string request_id = 2 [
    (google.api.field_info).format = UUID4,
    (google.api.field_behavior) = OPTIONAL
  ];
}

// Request message for updating a backup plan association.
message UpdateBackupPlanAssociationRequest {
  // Required. The resource being updated
  BackupPlanAssociation backup_plan_association = 1
      [(google.api.field_behavior) = REQUIRED];

  // Required. The list of fields to update.
  // Field mask is used to specify the fields to be overwritten in the
  // BackupPlanAssociation resource by the update.
  // The fields specified in the update_mask are relative to the resource, not
  // the full request. A field will be overwritten if it is in the mask. If the
  // user does not provide a mask then the request will fail.
  // Currently backup_plan_association.backup_plan is the only supported field.
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = REQUIRED];

  // Optional. An optional request ID to identify requests. Specify a unique
  // request ID so that if you must retry your request, the server will know to
  // ignore the request if it has already been completed. The server will
  // guarantee that for at least 60 minutes since the first request.
  //
  // For example, consider a situation where you make an initial request and t
  // he request times out. If you make the request again with the same request
  // ID, the server can check if original operation with the same request ID
  // was received, and if so, will ignore the second request. This prevents
  // clients from accidentally creating duplicate commitments.
  //
  // The request ID must be a valid UUID with the exception that zero UUID is
  // not supported (00000000-0000-0000-0000-000000000000).
  string request_id = 3 [
    (google.api.field_info).format = UUID4,
    (google.api.field_behavior) = OPTIONAL
  ];
}

// Request message for triggering a backup.
message TriggerBackupRequest {
  // Required. Name of the backup plan association resource, in the format
  // `projects/{project}/locations/{location}/backupPlanAssociations/{backupPlanAssociationId}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/BackupPlanAssociation"
    }
  ];

  // Required. backup rule_id for which a backup needs to be triggered.
  string rule_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Optional. An optional request ID to identify requests. Specify a unique
  // request ID so that if you must retry your request, the server will know to
  // ignore the request if it has already been completed. The server will
  // guarantee that for at least 60 minutes after the first request.
  //
  // For example, consider a situation where you make an initial request and
  // the request times out. If you make the request again with the same request
  // ID, the server can check if original operation with the same request ID
  // was received, and if so, will ignore the second request. This prevents
  // clients from accidentally creating duplicate commitments.
  //
  // The request ID must be a valid UUID with the exception that zero UUID is
  // not supported (00000000-0000-0000-0000-000000000000).
  string request_id = 3 [
    (google.api.field_info).format = UUID4,
    (google.api.field_behavior) = OPTIONAL
  ];
}
