// 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/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/field_info.proto";
import "google/api/resource.proto";
import "google/protobuf/timestamp.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 = "ProtectionSummaryProto";
option java_package = "com.google.cloud.backupdr.v1";
option php_namespace = "Google\\Cloud\\BackupDR\\V1";
option ruby_package = "Google::Cloud::BackupDR::V1";

// The Protection Summary service.
service BackupDrProtectionSummary {
  option (google.api.default_host) = "backupdr.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/cloud-platform";

  // Lists ResourceBackupConfigs.
  rpc ListResourceBackupConfigs(ListResourceBackupConfigsRequest)
      returns (ListResourceBackupConfigsResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/resourceBackupConfigs"
    };
    option (google.api.method_signature) = "parent";
  }
}

// Request for ListResourceBackupConfigs.
message ListResourceBackupConfigsRequest {
  // Required. The project and location for which to retrieve resource backup
  // configs. Format: 'projects/{project_id}/locations/{location}'. 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) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // Optional. Requested page size. Server may return fewer items than
  // requested. If unspecified, server will use 100 as default. Maximum value is
  // 500 and values above 500 will be coerced to 500.
  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];

  // Optional. Hint for how to order the results.
  string order_by = 5 [(google.api.field_behavior) = OPTIONAL];
}

// Response for ListResourceBackupConfigs.
message ListResourceBackupConfigsResponse {
  // The list of ResourceBackupConfigs for the specified scope.
  repeated ResourceBackupConfig resource_backup_configs = 1;

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

// ResourceBackupConfig represents a resource along with its backup
// configurations.
message ResourceBackupConfig {
  option (google.api.resource) = {
    type: "backupdr.googleapis.com/ResourceBackupConfig"
    pattern: "projects/{project}/locations/{location}/resourceBackupConfigs/{resource_backup_config}"
    plural: "resourceBackupConfigs"
    singular: "resourceBackupConfig"
  };

  // The type of the cloud resource.
  enum ResourceType {
    // Resource type not set.
    RESOURCE_TYPE_UNSPECIFIED = 0;

    // Cloud SQL instance.
    CLOUD_SQL_INSTANCE = 1;

    // Compute Engine VM.
    COMPUTE_ENGINE_VM = 2;

    // Compute Engine Disk.
    COMPUTE_ENGINE_DISK = 3;

    // Compute Engine Regional Disk.
    COMPUTE_ENGINE_REGIONAL_DISK = 4;
  }

  // Identifier. The resource name of the ResourceBackupConfig.
  // Format:
  // projects/{project}/locations/{location}/resourceBackupConfigs/{uid}
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Output only. The unique identifier of the resource backup config.
  string uid = 2 [
    (google.api.field_info).format = UUID4,
    (google.api.field_behavior) = OUTPUT_ONLY
  ];

  // Output only. The [full resource
  // name](https://cloud.google.com/asset-inventory/docs/resource-name-format)
  // of the cloud resource that this configuration applies to. Supported
  // resource types are
  // [ResourceBackupConfig.ResourceType][google.cloud.backupdr.v1.ResourceBackupConfig.ResourceType].
  string target_resource = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The human friendly name of the target resource.
  string target_resource_display_name = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The type of the target resource.
  ResourceType target_resource_type = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Labels associated with the target resource.
  map<string, string> target_resource_labels = 6;

  // Backup configurations applying to the target resource, including those
  // targeting its related/child resources. For example, backup configuration
  // applicable to Compute Engine disks will be populated in this field for a
  // Compute Engine VM which has the disk associated.
  repeated BackupConfigDetails backup_configs_details = 7;

  // Output only. Whether the target resource is configured for backup. This is
  // true if the backup_configs_details is not empty.
  bool backup_configured = 8 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Whether the target resource is protected by a backup vault.
  // This is true if the backup_configs_details is not empty and any of the
  // [ResourceBackupConfig.backup_configs_details][google.cloud.backupdr.v1.ResourceBackupConfig.backup_configs_details]
  // has a backup configuration with
  // [BackupConfigDetails.backup_vault][google.cloud.backupdr.v1.BackupConfigDetails.backup_vault]
  // set. set.
  bool vaulted = 9 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// BackupConfigDetails has information about how the resource is configured
// for backups and about the most recent backup taken for this configuration.
message BackupConfigDetails {
  // Type of the backup configuration.
  // This enum may receive new values in the future.
  enum Type {
    // Backup config type is unspecified.
    TYPE_UNSPECIFIED = 0;

    // Backup config is Cloud SQL instance's automated backup config.
    CLOUD_SQL_INSTANCE_BACKUP_CONFIG = 1;

    // Backup config is Compute Engine Resource Policy.
    COMPUTE_ENGINE_RESOURCE_POLICY = 2;

    // Backup config is Google Cloud Backup and DR's Backup Plan.
    BACKUPDR_BACKUP_PLAN = 3;

    // Backup config is Google Cloud Backup and DR's Template.
    BACKUPDR_TEMPLATE = 4;
  }

  // The state tells whether the backup config is active or not.
  enum State {
    // Backup config state not set.
    STATE_UNSPECIFIED = 0;

    // The config is in an active state protecting the resource
    ACTIVE = 1;

    // The config is currently not protecting the resource. Either because it is
    // disabled or the owning project has been deleted without cleanup of the
    // actual resource.
    INACTIVE = 2;

    // The config still exists but because of some error state it is not
    // protecting the resource. Like the source project is deleted. For eg.
    // PlanAssociation, BackupPlan is deleted.
    ERROR = 3;
  }

  // Output only. The full resource name of the backup config source resource.
  // For example,
  // "//backupdr.googleapis.com/v1/projects/{project}/locations/{region}/backupPlans/{backupplanId}"
  // or
  // "//compute.googleapis.com/projects/{project}/locations/{region}/resourcePolicies/{resourcePolicyId}".
  string backup_config_source = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The display name of the backup config source resource.
  string backup_config_source_display_name = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The type of the backup config resource.
  Type type = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The state of the backup config resource.
  State state = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Point in time recovery settings of the backup configuration
  // resource.
  PitrSettings pitr_settings = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp of the latest successful backup created via this
  // backup configuration.
  google.protobuf.Timestamp latest_successful_backup_time = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The [full resource
  // name](https://cloud.google.com/asset-inventory/docs/resource-name-format)
  // of the resource that is applicable for the backup configuration. Example:
  // "//compute.googleapis.com/projects/{project}/zones/{zone}/instances/{instance}"
  string applicable_resource = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The [full resource
  // name](https://cloud.google.com/asset-inventory/docs/resource-name-format)
  // of the backup vault that will store the backups generated through this
  // backup configuration. Example:
  // "//backupdr.googleapis.com/v1/projects/{project}/locations/{region}/backupVaults/{backupvaultId}"
  string backup_vault = 8 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The locations where the backups are to be stored.
  repeated BackupLocation backup_locations = 12;

  // The plan specific config. This depends on the value of
  // [BackupConfigDetails.type][google.cloud.backupdr.v1.BackupConfigDetails.type].
  // For type=BACKUPDR_BACKUP_PLAN, backup_dr_plan_config would be populated to
  // capture information related to Google Cloud Backup and DR's Backup Plans.
  // For type=BACKUPDR_TEMPLATE, backup_dr_template_config would be populated to
  // capture information related to Google Cloud Backup and DR's Template
  // details.
  oneof plan_specific_config {
    // Google Cloud Backup and DR's Backup Plan specific data.
    BackupDrPlanConfig backup_dr_plan_config = 10;

    // Google Cloud Backup and DR's Template specific data.
    BackupDrTemplateConfig backup_dr_template_config = 11;
  }
}

// Point in time recovery settings of the backup configuration resource.
message PitrSettings {
  // Output only. Number of days to retain the backup.
  int32 retention_days = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Provides additional information about Google Cloud Backup
// and DR's Template backup configuration.
message BackupDrTemplateConfig {
  // Output only. The URI of the BackupDr template resource for the first party
  // identity users.
  string first_party_management_uri = 1
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The URI of the BackupDr template resource for the third party
  // identity users.
  string third_party_management_uri = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// BackupDrPlanConfig has additional information about Google Cloud Backup and
// DR's Plan backup configuration.
message BackupDrPlanConfig {
  // Backup rules of the backup plan resource.
  repeated BackupDrPlanRule backup_dr_plan_rules = 1;
}

// BackupDrPlanRule has rule specific information of the backup plan resource.
message BackupDrPlanRule {
  // Output only. Unique Id of the backup rule.
  string rule_id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp of the latest successful backup created via this
  // backup rule.
  google.protobuf.Timestamp last_successful_backup_time = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// BackupLocation represents a cloud location where a backup can be stored.
message BackupLocation {
  // The type of the location.
  enum Type {
    // Location type is unspecified.
    TYPE_UNSPECIFIED = 0;

    // Location type is zonal.
    ZONAL = 1;

    // Location type is regional.
    REGIONAL = 2;

    // Location type is multi regional.
    MULTI_REGIONAL = 3;
  }

  // Output only. The type of the location.
  Type type = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The id of the cloud location. Example: "us-central1"
  string location_id = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
}
