syntax = "proto3";

package tidb_cloud_open_api.serverless.v1beta1;

import "google/api/field_behavior.proto";
import "google/api/field_info.proto";
import "google/protobuf/timestamp.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
import "tidb_cloud_open_api/common/v1beta1/clusterstate.proto";
import "tidb_cloud_open_api/common/v1beta1/engine_type.proto";
import "tidb_cloud_open_api/common/v1beta1/region.proto";
import "tidb_cloud_open_api/common/v1beta1/service_plan.proto";
import "tidb_cloud_open_api/common/v1beta1/tag.proto";

option go_package = "tidb_cloud_open_api/serverless/v1beta1";

// Message for a TiDB Cloud Starter or Essential cluster.
message Cluster {
  // Message for audit log configuration.
  message AuditLogConfig {
    // Whether audit log is enabled.
    optional bool enabled = 1 [(google.api.field_behavior) = OPTIONAL];
    // Whether unredacted the audit log.
    optional bool unredacted = 2 [(google.api.field_behavior) = OPTIONAL];
  }

  // Message for spending limit configuration.
  message SpendingLimit {
    // The maximum spending limit for the cluster per month, in USD cents.
    int32 monthly = 1 [(google.api.field_behavior) = OPTIONAL];
  }

  // Message for auto scaling configuration.
  message AutoScaling {
    // The minimum number of Request Capacity Units (RCUs) for auto-scaling.
    uint32 min_rcu = 1 [(google.api.field_behavior) = OPTIONAL];
    // The maximum number of Request Capacity Units (RCUs) for auto-scaling.
    uint32 max_rcu = 2 [(google.api.field_behavior) = OPTIONAL];
  }

  // Message for automated backup configuration for a cluster.
  message AutomatedBackupPolicy {
    // The UTC time of day in `HH:mm` format when the automated backup starts.
    string start_time = 1 [(google.api.field_behavior) = OPTIONAL];

    // The number of days to retain automated backups.
    int32 retention_days = 2 [(google.api.field_behavior) = OPTIONAL];
  }

  // Message for endpoint information for connecting to a cluster.
  message Endpoints {
    // Message for public endpoint to connect to the cluster.
    message Public {
      // The hostname of the public endpoint.
      string host = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

      // The port number of the public endpoint
      int32 port = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

      // Indicates whether the public endpoint is disabled.
      bool disabled = 3 [(google.api.field_behavior) = OPTIONAL];

      message AuthorizedNetwork {
        // The starting IP address of the authorized network range.
        string start_ip_address = 1 [
          (google.api.field_info).format = IPV4,
          (google.api.field_behavior) = REQUIRED
        ];
        // The ending IP address of the authorized network range.
        string end_ip_address = 2 [
          (google.api.field_info).format = IPV4,
          (google.api.field_behavior) = REQUIRED
        ];
        // The display name of the authorized network.
        string display_name = 3 [(google.api.field_behavior) = REQUIRED];
      }

      // The list of networks that are allowed to connect to the cluster.
      repeated AuthorizedNetwork authorized_networks = 4 [(google.api.field_behavior) = OPTIONAL];
    }

    // Message for private endpoint to securely connect to the cluster.
    message Private {
      message AuthorizedNetwork {
        string vpc_endpoint_id = 1 [(google.api.field_behavior) = REQUIRED];
        string display_name = 2 [(google.api.field_behavior) = REQUIRED];
      }

      // The [AWS PrivateLink](https://aws.amazon.com/privatelink/) configuration details for private access.
      message AWS {
        // The AWS service name for private access.
        string service_name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

        // A list of availability zones where the service is available.
        repeated string availability_zone = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
      }

      // Message for GCP Private Service information.
      message GCP {
        // The target GCP service attachment name for private access.
        string service_attachment_name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
      }

      // The [Alibaba Cloud PrivateLink](https://www.alibabacloud.com/help/en/privatelink/product-overview/what-is-a-private-network-connection) configuration for private access.
      message ALICLOUD {
        // The Alibaba Cloud service name for private access.
        string service_name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

        // A list of availability zones where the service is available.
        repeated string availability_zone = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
      }

      // The hostname of the private endpoint.
      string host = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

      // The port number of the private endpoint.
      int32 port = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

      // Cloud provider specific details.
      oneof provider {
        AWS aws = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

        GCP gcp = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

        ALICLOUD alicloud = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
      }

      repeated AuthorizedNetwork authorized_networks = 7 [(google.api.field_behavior) = OPTIONAL];
    }

    // The public endpoint configuration for connecting to the cluster. For more information, see [Network](https://docs.pingcap.com/tidbcloud/connect-to-tidb-cluster-serverless/#network).
    Public public = 1 [(google.api.field_behavior) = OPTIONAL];

    // The private endpoint for securely connecting to the cluster. For more information, see [Network](https://docs.pingcap.com/tidbcloud/connect-to-tidb-cluster-serverless/#network).
    Private private = 2 [(google.api.field_behavior) = OPTIONAL];
  }

  // Message for encryption settings for a cluster.
  message EncryptionConfig {
    // Indicates whether enhanced encryption for cluster data is enabled.
    bool enhanced_encryption_enabled = 1 [(google.api.field_behavior) = OPTIONAL];
  }

  // The high availability configuration for the cluster.
  //
  // - `ZONAL`: high availability within a single availability zone. For more information, see [Zonal high availability architecture](https://docs.pingcap.com/tidbcloud/serverless-high-availability/#zonal-high-availability-architecture).
  // - `REGIONAL`: high availability across multiple availability zones within a region. For more information, see [Regional high availability architecture](https://docs.pingcap.com/tidbcloud/serverless-high-availability/#regional-high-availability-architecture).
  enum HighAvailabilityType {
    // This is an unknown high availability type
    HIGH_AVAILABILITY_TYPE_UNSPECIFIED = 0;

    ZONAL = 1;

    REGIONAL = 2;
  }

  // The unique identifier for the TiDB cluster, which is generated by the API and follows the format `clusters/{clusterId}`.
  string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The ID of the cluster.
  string cluster_id = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The user-defined name of the cluster.
  string display_name = 3 [
    (google.api.field_behavior) = REQUIRED,
    (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
      pattern: "^[A-Za-z0-9][-A-Za-z0-9]{2,62}[A-Za-z0-9]$"
      example: "\"foo-bar\""
      min_length: 4
      max_length: 64
    }
  ];

  // The region where the cluster is deployed.
  common.v1beta1.Region region = 4 [(google.api.field_behavior) = REQUIRED];

  // The [spending limit](https://docs.pingcap.com/tidbcloud/tidb-cloud-glossary/#spending-limit) for the cluster.
  SpendingLimit spending_limit = 5 [(google.api.field_behavior) = OPTIONAL];

  // The schedule and retention rules for automated database backups.
  AutomatedBackupPolicy automated_backup_policy = 6 [(google.api.field_behavior) = OPTIONAL];

  // The connection endpoints for accessing the cluster.
  Endpoints endpoints = 7 [(google.api.field_behavior) = OPTIONAL];

  // The root password of the cluster. It must be between 8 and 64 characters long and can contain letters, numbers, and special characters.
  string root_password = 8 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.field_behavior) = INPUT_ONLY,
    (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
      pattern: "^.{8,64}$"
      example: "\"my-shining-password\""
      min_length: 8
      max_length: 64
    }
  ];

  // The data encryption settings for the cluster.
  EncryptionConfig encryption_config = 9 [(google.api.field_behavior) = OPTIONAL];

  HighAvailabilityType high_availability_type = 10 [(google.api.field_behavior) = OPTIONAL];

  // The TiDB version of the cluster.
  string version = 20 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The email address of the user who create the cluster.
  string created_by = 21 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The unique prefix automatically generated for SQL usernames on this cluster. TiDB Cloud uses this prefix to distinguish between clusters. For more information, see [User name prefix](https://docs.pingcap.com/tidbcloud/select-cluster-tier/#user-name-prefix).
  string user_prefix = 22 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The current state of the cluster.
  common.v1beta1.ClusterState state = 23 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The labels for the cluster.
  //
  // - `tidb.cloud/organization`: the ID of the organization where the cluster belongs.
  // - `tidb.cloud/project`: the ID of the project where the cluster belongs.
  map<string, string> labels = 25 [(google.api.field_behavior) = OPTIONAL];

  // The annotations for the cluster. The following lists some predefined annotations.
  //
  // - `tidb.cloud/has-set-password`: indicates whether the cluster has a root password set.
  // - `tidb.cloud/available-features`: lists available features of the cluster.
  map<string, string> annotations = 26 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The timestamp when the cluster was created, in the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
  google.protobuf.Timestamp create_time = 27 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The timestamp when the cluster was last updated, in the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
  google.protobuf.Timestamp update_time = 28 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The audit log configuration for the cluster.
  AuditLogConfig audit_log_config = 29 [(google.api.field_behavior) = OPTIONAL];

  // The auto-scaling configuration for the cluster.
  AutoScaling auto_scaling = 31 [(google.api.field_behavior) = OPTIONAL];

  // The plan of the service.
  //
  // - `Starter`: [TiDB Cloud Starter](https://docs.pingcap.com/tidbcloud/select-cluster-tier/#tidb-cloud-serverless)
  // - `Essential`: [TiDB Cloud Essential](https://docs.pingcap.com/tidbcloud/select-cluster-tier/#essential)
  common.v1beta1.ServicePlan service_plan = 32 [(google.api.field_behavior) = OUTPUT_ONLY];

  repeated common.v1beta1.Tag tags = 33 [(google.api.field_behavior) = OPTIONAL];

  // The database engine compatibility of the cluster.
  //
  // - `MYSQL_COMPATIBLE`: TiDB Starter/Essential MySQL-compatible engine.
  // - `POSTGRESQL_COMPATIBLE`: TiDB Starter PostgreSQL-compatible engine.
  common.v1beta1.EngineType engine_type = 34 [(google.api.field_behavior) = OPTIONAL];
}

// Message for a shadow pool used by TiDB Cloud Starter.
message ShadowPool {
  // Message for instance demand limits.
  message InstanceDemand {
    uint64 monthly_spending_limit = 1 [(google.api.field_behavior) = OPTIONAL];
  }

  // The ID of the shadow pool.
  string shadow_pool_id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The user-defined name of the shadow pool.
  string name = 2 [(google.api.field_behavior) = REQUIRED];

  // The organization ID where the shadow pool belongs.
  string organization_id = 3 [(google.api.field_behavior) = REQUIRED];

  // The project ID where the shadow pool belongs.
  string project_id = 4 [(google.api.field_behavior) = REQUIRED];

  // The region where the shadow pool is deployed, in the format `regions/{provider}-{region}`.
  string region = 5 [(google.api.field_behavior) = REQUIRED];

  // The cloud provider where the shadow pool is deployed.
  common.v1beta1.Region.CloudProvider cloud_provider = 6 [(google.api.field_behavior) = REQUIRED];

  // The plan of the service.
  //
  // Currently, only `Starter` is supported for shadow pool APIs.
  common.v1beta1.ServicePlan service_plan = 7 [(google.api.field_behavior) = REQUIRED];

  // Whether the shadow pool is enabled.
  bool enabled = 8 [(google.api.field_behavior) = OPTIONAL];

  // The minimum number of prepared instances.
  int32 min_capacity = 9 [(google.api.field_behavior) = OPTIONAL];

  // The spending and RCU demand configuration.
  InstanceDemand instance_demand = 11 [(google.api.field_behavior) = OPTIONAL];

  // SQL statements to execute during cluster initialization.
  repeated string init_sqls = 12 [(google.api.field_behavior) = OPTIONAL];

  // The number of available prepared clusters in this shadow pool.
  uint32 available_clusters_count = 13 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The timestamp when the shadow pool was created, in the ISO 8601 format.
  google.protobuf.Timestamp create_time = 100 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The timestamp when the shadow pool was last updated, in the ISO 8601 format.
  google.protobuf.Timestamp update_time = 101 [(google.api.field_behavior) = OUTPUT_ONLY];
}
