syntax = "proto3";

package yandex.cloud.ydb.v1;

import "google/protobuf/timestamp.proto";
import "yandex/cloud/validation.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";

// YDB database.
message Database {
  enum Status {
    STATUS_UNSPECIFIED = 0;
    PROVISIONING = 1;
    RUNNING = 2;
    UPDATING = 4;
    ERROR = 5;
    DELETING = 6;
    STARTING = 7;
    STOPPED = 8;
  }

  string id = 1;

  string folder_id = 2;

  google.protobuf.Timestamp created_at = 3;

  string name = 4;

  string description = 5;

  Status status = 6;

  string endpoint = 8;
  string resource_preset_id = 9;

  StorageConfig storage_config = 10;
  ScalePolicy scale_policy = 11;

  string network_id = 12;
  repeated string subnet_ids = 13;

  oneof database_type {
    // deprecated field
    ZonalDatabase zonal_database = 14;
    // deprecated field
    RegionalDatabase regional_database = 15;
    DedicatedDatabase dedicated_database = 18;
    ServerlessDatabase serverless_database = 19;
  }

  bool assign_public_ips = 16;
  string location_id = 17;
  map<string, string> labels = 20;

  BackupConfig backup_config = 21;

  string document_api_endpoint = 22;

  string kinesis_api_endpoint = 23;
}

message DedicatedDatabase {
  string resource_preset_id = 1;
  StorageConfig storage_config = 2;
  ScalePolicy scale_policy = 3;
  string network_id = 4;
  repeated string subnet_ids = 5;
  bool assign_public_ips = 6;
}

message ServerlessDatabase {
  // Let's define 1 RU  - 1 request unit
  // Let's define 1 RCU - 1 request capacity unit, which is 1 RU per second.
  // If `enable_throttling_rcu_limit` flag is true, the database will be throttled using `throttling_rcu_limit` value.
  // Otherwise, the database is throttled using the cloud quotas.
  // If zero, all requests will be blocked until non zero value is set.
  int64 throttling_rcu_limit = 1;
  // Specify serverless database storage size limit. If zero, default value is applied.
  int64 storage_size_limit = 2;
  // If false, the database is throttled by cloud value.
  bool enable_throttling_rcu_limit = 3;
  // Specify the number of provisioned RCUs to pay less if the database has predictable load.
  // You will be charged for the provisioned capacity regularly even if this capacity is not fully consumed.
  // You will be charged for the on-demand consumption only if provisioned capacity is consumed.
  int64 provisioned_rcu_limit = 4;
}

message ZonalDatabase {
  string zone_id = 1 [(required) = true];
}

message RegionalDatabase {
  string region_id = 1 [(required) = true];
}

message ScalePolicy {
  oneof scale_type {
    option (exactly_one) = true;
    FixedScale fixed_scale = 1;
  }

  message FixedScale {
    int64 size = 1 [(yandex.cloud.value) = ">=1"];
  }
}

message StorageConfig {
   repeated StorageOption storage_options = 1 [(size) = ">=1"];
   // output only field: storage size limit of dedicated database.
   int64 storage_size_limit = 2;
}

message StorageOption {
  string storage_type_id = 1;
  int64 group_count = 2;
}
