// 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/resource.proto";
import "google/cloud/backupdr/v1/backupvault.proto";
import "google/cloud/backupdr/v1/backupvault_cloudsql.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 = "DataSourceReferenceProto";
option java_package = "com.google.cloud.backupdr.v1";
option php_namespace = "Google\\Cloud\\BackupDR\\V1";
option ruby_package = "Google::Cloud::BackupDR::V1";

// DataSourceReference is a reference to a DataSource resource.
message DataSourceReference {
  option (google.api.resource) = {
    type: "backupdr.googleapis.com/DataSourceReference"
    pattern: "projects/{project}/locations/{location}/dataSourceReferences/{data_source_reference}"
    plural: "dataSourceReferences"
    singular: "dataSourceReference"
  };

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

  // Output only. The resource name of the DataSource.
  // Format:
  // projects/{project}/locations/{location}/backupVaults/{backupVault}/dataSources/{dataSource}
  string data_source = 2 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/DataSource"
    }
  ];

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

  // Output only. The backup configuration state of the DataSource.
  BackupConfigState data_source_backup_config_state = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Number of backups in the DataSource.
  int64 data_source_backup_count = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Information of backup configuration on the DataSource.
  DataSourceBackupConfigInfo data_source_backup_config_info = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The GCP resource that the DataSource is associated with.
  DataSourceGcpResourceInfo data_source_gcp_resource_info = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Total size of the storage used by all backup resources for the
  // referenced datasource.
  optional int64 total_stored_bytes = 8
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Information of backup configuration on the DataSource.
message DataSourceBackupConfigInfo {
  // Output only. The status of the last backup in this DataSource
  BackupConfigInfo.LastBackupState last_backup_state = 1
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp of the last successful backup to this DataSource.
  google.protobuf.Timestamp last_successful_backup_consistency_time = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// The GCP resource that the DataSource is associated with.
message DataSourceGcpResourceInfo {
  // Output only. The resource name of the GCP resource.
  // Ex: projects/{project}/zones/{zone}/instances/{instance}
  string gcp_resourcename = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The type of the GCP resource.
  // Ex: compute.googleapis.com/Instance
  string type = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The location of the GCP resource.
  // Ex: <region>/<zone>/"global"/"unspecified"
  string location = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The properties of the GCP resource.
  oneof resource_properties {
    // Output only. The properties of the Cloud SQL instance.
    CloudSqlInstanceDataSourceReferenceProperties
        cloud_sql_instance_properties = 4
        [(google.api.field_behavior) = OUTPUT_ONLY];
  }
}

// Request for the GetDataSourceReference method.
message GetDataSourceReferenceRequest {
  // Required. The name of the DataSourceReference to retrieve.
  // Format:
  // projects/{project}/locations/{location}/dataSourceReferences/{data_source_reference}
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "backupdr.googleapis.com/DataSourceReference"
    }
  ];
}

// Request for the ListDataSourceReferences method.
message ListDataSourceReferencesRequest {
  // 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/DataSourceReference"
    }
  ];

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

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

  // Optional. A filter expression that filters the results listed in the
  // response. The expression must specify the field name, a comparison
  // operator, and the value that you want to use for filtering.
  //
  // The following field and operator combinations are supported:
  //
  // * data_source_gcp_resource_info.gcp_resourcename with `=`, `!=`
  // * data_source_gcp_resource_info.type with `=`, `!=`
  string filter = 4 [(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:
  //
  // * data_source
  // * data_source_gcp_resource_info.gcp_resourcename
  string order_by = 5 [(google.api.field_behavior) = OPTIONAL];
}

// Response for the ListDataSourceReferences method.
message ListDataSourceReferencesResponse {
  // The DataSourceReferences from the specified parent.
  repeated DataSourceReference data_source_references = 1;

  // 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;

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

// Request for the FetchDataSourceReferencesForResourceType method.
message FetchDataSourceReferencesForResourceTypeRequest {
  // 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/DataSourceReference"
    }
  ];

  // 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 DataSourceReferences to return. The service
  // may return fewer than this value. If unspecified, at most 50
  // DataSourceReferences 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
  // `FetchDataSourceReferencesForResourceType`.
  // Provide this to retrieve the subsequent page.
  //
  // When paginating, all other parameters provided to
  // `FetchDataSourceReferencesForResourceType` 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:
  // * data_source
  // * data_source_gcp_resource_info.gcp_resourcename
  // * data_source_backup_config_state
  // * data_source_backup_count
  // * data_source_backup_config_info.last_backup_state
  // * data_source_gcp_resource_info.gcp_resourcename
  // * data_source_gcp_resource_info.type
  // * data_source_gcp_resource_info.location
  // * data_source_gcp_resource_info.cloud_sql_instance_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 FetchDataSourceReferencesForResourceType method.
message FetchDataSourceReferencesForResourceTypeResponse {
  // The DataSourceReferences from the specified parent.
  repeated DataSourceReference data_source_references = 1;

  // 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;
}
