syntax = "proto3";

package yandex.cloud.ydb.v1;

import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "yandex/cloud/api/operation.proto";
import "yandex/cloud/operation/operation.proto";
import "yandex/cloud/validation.proto";
import "yandex/cloud/ydb/v1/database.proto";
import "yandex/cloud/ydb/v1/backup.proto";

option go_package = "github.com/yandex-cloud/go-genproto/yandex/cloud/ydb/v1;ydb";
option java_package = "yandex.cloud.api.ydb.v1";

// A set of methods for managing databases.
service DatabaseService {
  // Returns the specified database.
  rpc Get (GetDatabaseRequest) returns (Database) {
     option (google.api.http) = { get: "/ydb/v1/databases/{database_id}" };
  }

  // Retrieves a list of databases.
  rpc List (ListDatabasesRequest) returns (ListDatabasesResponse) {
     option (google.api.http) = { get: "/ydb/v1/databases" };
  }

  // Creates a new database.
  rpc Create (CreateDatabaseRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/ydb/v1/databases" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "CreateDatabaseMetadata"
      response: "Database"
    };
  }

  // Modifies the specified database.
  rpc Update (UpdateDatabaseRequest) returns (operation.Operation) {
    option (google.api.http) = { patch: "/ydb/v1/databases/{database_id}" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "UpdateDatabaseMetadata"
      response: "Database"
    };
  }

  // Starts the specified database.
  rpc Start (StartDatabaseRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/ydb/v1/databases/{database_id}:start" };
    option (yandex.cloud.api.operation) = {
      metadata: "StartDatabaseMetadata"
      response: "Database"
    };
  }

  // Stops the specified database.
  rpc Stop (StopDatabaseRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/ydb/v1/databases/{database_id}:stop" };
    option (yandex.cloud.api.operation) = {
      metadata: "StopDatabaseMetadata"
      response: "Database"
    };
  }

  // Deletes the specified database.
  rpc Delete (DeleteDatabaseRequest) returns (operation.Operation) {
    option (google.api.http) = { delete: "/ydb/v1/databases/{database_id}" };
    option (yandex.cloud.api.operation) = {
      metadata: "DeleteDatabaseMetadata"
      response: "google.protobuf.Empty"
    };
  }

  // Restores the specified backup
  rpc Restore (RestoreBackupRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/ydb/v1/databases:restore" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "RestoreBackupMetadata"
      response: "Database"
    };
  }

  rpc Backup(BackupDatabaseRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/ydb/v1/databases:backup" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "BackupDatabaseMetadata"
      response: "Database"
    };
  }
}


message RestoreBackupRequest {
  // Required. ID of the YDB backup.
  string backup_id = 1 [(required) = true, (length) = "<=50"];
  // Required. ID of the YDB database.
  string database_id = 2 [(required) = true, (length) = "<=50"];
  // Specify paths to restore.
  // If empty, all paths will restored by default.
  repeated string paths_to_restore = 3;
  // Specify target path.
  string target_path = 4;
}

message RestoreBackupMetadata {
  string backup_id = 1;
  string database_id = 2;
}

message BackupDatabaseRequest {
  string database_id = 1;
  // custom backup options, if required.
  BackupSettings backup_settings = 2;
}

message BackupDatabaseMetadata {
  string backup_id = 1;
  string database_id = 2;
}

message StartDatabaseRequest {
  string database_id = 1 [(required) = true, (length) = "<=50"];
}


message StartDatabaseMetadata {
  string database_id = 1;
  string database_name = 2;
}


message StopDatabaseRequest {
  string database_id = 1 [(required) = true, (length) = "<=50"];
}


message StopDatabaseMetadata {
  string database_id = 1;
  string database_name = 2;
}


message GetDatabaseRequest {
  // Required. ID of the YDB cluster.
  string database_id = 1 [(required) = true, (length) = "<=50"];
}

message ListDatabasesRequest {
  string folder_id = 1;

  // The maximum number of results per page that should be returned. If the number of available
  // results is larger than `page_size`, the service returns a `next_page_token` that can be used
  // to get the next page of results in subsequent ListDatabases requests.
  // Acceptable values are 0 to 1000, inclusive. Default value: 100.
  int64 page_size = 2 [(value) = "0-1000"];

  // Page token. Set `page_token` to the `next_page_token` returned by a previous ListDatabases
  // request to get the next page of results.
  string page_token = 3 [(length) = "<=100"];
}

message ListDatabasesResponse {
  repeated Database databases = 1;

  // This token allows you to get the next page of results for ListDatabases requests,
  // if the number of results is larger than `page_size` specified in the request.
  // To get the next page, specify the value of `next_page_token` as a value for
  // the `page_token` parameter in the next ListDatabases request. Subsequent ListDatabases
  // requests will have their own `next_page_token` to continue paging through the results.
  string next_page_token = 2;
}

message CreateDatabaseRequest {
  string folder_id = 1;

  string name = 2;

  string description = 3;

  string resource_preset_id = 4;

  StorageConfig storage_config = 5;
  ScalePolicy scale_policy = 6;
  string network_id = 7;
  repeated string subnet_ids = 8;

  oneof database_type {
    // deprecated field
    ZonalDatabase zonal_database = 9;
    // deprecated field
    RegionalDatabase regional_database = 10;
    DedicatedDatabase dedicated_database = 13;
    ServerlessDatabase serverless_database = 14;
  }

  bool assign_public_ips = 11;
  string location_id = 12;
  map<string, string> labels = 15;
  BackupConfig backup_config = 16;
}

message CreateDatabaseMetadata {
  // Required. ID of the YDB cluster.
  string database_id = 1;

  // Required. Name of the creating database.
  string database_name = 2;
}

message UpdateDatabaseRequest {
  string folder_id = 1;
  google.protobuf.FieldMask update_mask = 2;

  string database_id = 3;

  string name = 4;

  string description = 5;

  string resource_preset_id = 6;
  StorageConfig storage_config = 7;
  ScalePolicy scale_policy = 8;
  string network_id = 9;
  repeated string subnet_ids = 10;

  oneof database_type {
    ZonalDatabase zonal_database = 11;
    RegionalDatabase regional_database = 12;
    DedicatedDatabase dedicated_database = 15;
    ServerlessDatabase serverless_database = 16;
  }

  bool assign_public_ips = 13;
  string location_id = 14;
  map<string, string> labels = 17;
  BackupConfig backup_config = 18;
}

message UpdateDatabaseMetadata {
  string database_id = 1;
  string database_name = 2;
}

message DeleteDatabaseRequest {
  string database_id = 1;
}

message DeleteDatabaseMetadata {
  string database_id = 1;
  string database_name = 2;
}
