syntax = "proto3";

package global.nextgen.v1;

import "global/common/v1/service_plan.proto";
import "global/nextgen/v1/backup_common.proto";
import "google/api/field_behavior.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

// support br api in org level
service BackupService {
  rpc ListBackups(ListBackupsRequest) returns (ListBackupsResponse);
  rpc DeleteBackup(DeleteBackupRequest) returns (google.protobuf.Empty);
  rpc ListNotCleanupBackupSettings(ListNotCleanupBackupSettingsRequest) returns (ListNotCleanupBackupSettingsResponse);
  rpc BatchUpdateBackupSettingNames(BatchUpdateBackupSettingNamesRequest) returns (google.protobuf.Empty);
  rpc ListBackupPolicies(ListBackupPoliciesRequest) returns (ListBackupPoliciesResponse);
  rpc CreateManualBackup(CreateManualBackupRequest) returns (CreateManualBackupResponse);
  // Creates or returns the single final backup associated with a cluster.
  rpc CreateFinalBackup(CreateFinalBackupRequest) returns (CreateFinalBackupResponse);
  rpc OverrideFlexibleBackupRetention(OverrideFlexibleBackupRetentionRequest) returns (BackupSetting);
}

message OverrideFlexibleBackupRetentionRequest {
  string cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  int32 retention_days = 2 [(google.api.field_behavior) = REQUIRED];
  string reason = 3 [(google.api.field_behavior) = REQUIRED];
}

message ListBackupsRequest {
  enum ClusterState {
    CLUSTER_STATE_UNSPECIFIED = 0;
    ACTIVE = 1;
    DELETED = 2;
  }

  // filter fileds
  repeated string cluster_ids = 1 [(google.api.field_behavior) = OPTIONAL];
  repeated string organization_ids = 2 [(google.api.field_behavior) = OPTIONAL];
  repeated string backup_ids = 3 [(google.api.field_behavior) = OPTIONAL];
  repeated Backup.State states = 4 [(google.api.field_behavior) = OPTIONAL];
  repeated common.v1.ServicePlan service_plans = 5 [(google.api.field_behavior) = OPTIONAL];
  repeated string region_ids = 6 [(google.api.field_behavior) = OPTIONAL];
  repeated ClusterState cluster_states = 7 [(google.api.field_behavior) = OPTIONAL];
  repeated Backup.TriggerType trigger_types = 8 [(google.api.field_behavior) = OPTIONAL];
  google.protobuf.Timestamp start_time = 9 [(google.api.field_behavior) = OPTIONAL];
  google.protobuf.Timestamp end_time = 10 [(google.api.field_behavior) = OPTIONAL];

  // page fileds
  int32 page_size = 100 [(google.api.field_behavior) = OPTIONAL];
  string page_token = 101 [(google.api.field_behavior) = OPTIONAL];
  int32 skip = 102 [(.google.api.field_behavior) = OPTIONAL];
}

message ListBackupsResponse {
  repeated Backup backups = 1;

  //page fileds
  int32 total_size = 2;
  string next_page_token = 3;
}

message DeleteBackupRequest {
  string backup_id = 1 [(google.api.field_behavior) = REQUIRED];
  string organization_id = 2 [(google.api.field_behavior) = REQUIRED];
}

message ListNotCleanupBackupSettingsRequest {
  string organization_id = 1 [(google.api.field_behavior) = REQUIRED];
  repeated uint64 cluster_ids = 2 [(google.api.field_behavior) = OPTIONAL];
  repeated common.v1.ServicePlan service_plans = 3 [(google.api.field_behavior) = OPTIONAL];
  repeated string region_ids = 4 [(google.api.field_behavior) = OPTIONAL];
  google.protobuf.Timestamp start_time = 5 [(google.api.field_behavior) = OPTIONAL];
  google.protobuf.Timestamp end_time = 6 [(google.api.field_behavior) = OPTIONAL];
  string name = 7 [(google.api.field_behavior) = OPTIONAL];

  // page fileds
  int32 page_size = 100 [(google.api.field_behavior) = OPTIONAL];
  string page_token = 101 [(google.api.field_behavior) = OPTIONAL];
  int32 skip = 102 [(.google.api.field_behavior) = OPTIONAL];
}

message ListNotCleanupBackupSettingsResponse {
  repeated BackupSetting backup_settings = 1;
  int32 total_size = 2;
  string next_page_token = 3;
}

message BatchUpdateBackupSettingNamesRequest {
  message BackupSettingName {
    uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
    string name = 2 [(google.api.field_behavior) = REQUIRED];
  }

  string organization_id = 1 [(google.api.field_behavior) = REQUIRED];
  repeated BackupSettingName items = 2 [(google.api.field_behavior) = REQUIRED];
}

// (-- api-linter: core::0158::request-page-size-field=disabled aip.dev/not-precedent: the number of backup policy is small, paging is no need --)
// (-- api-linter: core::0158::request-page-token-field=disabled aip.dev/not-precedent: the number of backup policy is small, paging is no need --)
message ListBackupPoliciesRequest {
  string tidb_id = 1 [(google.api.field_behavior) = REQUIRED];
}

// (-- api-linter: core::0158::response-next-page-token-field=disabled  aip.dev/not-precedent: the number of backup policy is small, paging is no need --)
message ListBackupPoliciesResponse {
  repeated BackupSetting.BackupPolicy backup_policies = 1;
}

message CreateManualBackupRequest {
  string cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  string organization_id = 2 [(google.api.field_behavior) = REQUIRED];
  string name = 3 [(google.api.field_behavior) = REQUIRED];
}

message CreateManualBackupResponse {
  string backup_id = 1;
}

message CreateFinalBackupRequest {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
}

message CreateFinalBackupResponse {
  string backup_id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}
