syntax = "proto3";

package global.nextgen.v1;

import "global/common/v1/resources.proto";
import "google/api/field_behavior.proto";
import "google/protobuf/empty.proto";

service PrivateLinkConnectionService {
  rpc CreatePrivateLinkService(CreatePrivateLinkServiceRequest) returns (PrivateLinkService) {}
  rpc ListPrivateLinkServices(ListPrivateLinkServicesRequest) returns (ListPrivateLinkServicesResponse) {}
  rpc DeletePrivateLinkService(DeletePrivateLinkServiceRequest) returns (google.protobuf.Empty) {}

  rpc CreatePrivateLinkConnection(CreatePrivateLinkConnectionRequest) returns (PrivateLinkConnection) {}
  rpc GetPrivateLinkConnection(GetPrivateLinkConnectionRequest) returns (PrivateLinkConnection) {}
  rpc ListPrivateLinkConnections(ListPrivateLinkConnectionsRequest) returns (ListPrivateLinkConnectionsResponse) {}
  rpc DeletePrivateLinkConnection(DeletePrivateLinkConnectionRequest) returns (PrivateLinkConnection) {}
}

message PrivateLinkService {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  uint64 tidb_group_id = 2 [(google.api.field_behavior) = OPTIONAL];
  common.v1.Region.Name region_id = 3 [(google.api.field_behavior) = REQUIRED];
  string region_display_name = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
  common.v1.CloudProvider.Name cloud_provider_id = 5 [(google.api.field_behavior) = REQUIRED];
  // For AWS, it's VPC endpoint service name. If specified, TiDB Cloud will try to import existing VPC endpoint service. Otherwise, TiDB Cloud will create a new VPC endpoint service.
  string service_name = 6 [(google.api.field_behavior) = OPTIONAL];
  string service_dns_name = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
  repeated string available_zones = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
  int32 service_port = 9 [(google.api.field_behavior) = OUTPUT_ONLY];

  State state = 10 [(google.api.field_behavior) = OUTPUT_ONLY];

  enum State {
    STATE_UNSPECIFIED = 0;
    CREATING = 1;
    ACTIVE = 2;
    DELETING = 3;
  }
}

message ListPrivateLinkServicesRequest {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  uint64 tidb_group_id = 2 [(google.api.field_behavior) = OPTIONAL];
}

message ListPrivateLinkServicesResponse {
  repeated PrivateLinkService private_link_services = 1;
}

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

message CreatePrivateLinkServiceRequest {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  uint64 tidb_group_id = 2 [(google.api.field_behavior) = REQUIRED];
  PrivateLinkService private_link_service = 3 [(google.api.field_behavior) = OPTIONAL];
  // For AWS, if service_name of private_link_service is specified, TiDB Cloud will try to import existing VPC endpoint service
  // and private_link_connections. Otherwise, the private_link_connections field will be ignored.
  repeated PrivateLinkConnection private_link_connections = 4 [(google.api.field_behavior) = OPTIONAL];
}

message PrivateLinkConnection {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  uint64 tidb_group_id = 2 [(google.api.field_behavior) = OPTIONAL];
  common.v1.Region.Name region_id = 3 [(google.api.field_behavior) = REQUIRED];
  string region_display_name = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
  string private_link_connection_id = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
  common.v1.CloudProvider.Name cloud_provider_id = 7 [(google.api.field_behavior) = REQUIRED];
  // For AWS, it's VPC endpoint ID.
  // For GCP, it's private service connect endpoint ID.
  // For Azure, it's private endpoint resource ID.
  // For AliCloud, it's endpoint ID.
  string endpoint_id = 8 [(google.api.field_behavior) = REQUIRED];
  string message = 9 [(google.api.field_behavior) = OUTPUT_ONLY];

  State state = 10 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The private link service name.
  string private_link_service = 11 [(google.api.field_behavior) = OUTPUT_ONLY];
  // The private link service state.
  PrivateLinkService.State private_link_service_state = 12 [(google.api.field_behavior) = OUTPUT_ONLY];

  EndpointType endpoint_type = 13 [(google.api.field_behavior) = OUTPUT_ONLY];

  // For gcp and azure, different endpoints of a private link service have different hostnames.
  string host = 14 [(google.api.field_behavior) = OUTPUT_ONLY];

  string port = 15 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Only available for Azure clusters.
  // The private IP address of the private endpoint in the user's vNet.
  // TiDB Cloud will setup a public DNS record for this private IP address. So the user can use DNS address to connect to the cluster.
  string private_ip_address = 16 [(google.api.field_behavior) = OPTIONAL];

  // Only available for AliCloud clusters.
  // Use private endpoint's Domain name to generate new TiDB DNS name.
  string private_domain_name = 17 [(google.api.field_behavior) = OPTIONAL];

  enum State {
    STATE_UNSPECIFIED = 0;
    PENDING = 1;
    ACTIVE = 2;
    DELETING = 3;
    FAILED = 4;
    DISCOVERED = 5;
  }

  enum EndpointType {
    ENDPOINT_TYPE_UNSPECIFIED = 0;
    DBAAS = 1;
    CUSTOMER = 2;
  }
}

message CreatePrivateLinkConnectionRequest {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  uint64 tidb_group_id = 2 [(google.api.field_behavior) = OPTIONAL];
  PrivateLinkConnection private_link_connection = 3 [(google.api.field_behavior) = REQUIRED];
}

message ListPrivateLinkConnectionsRequest {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  uint64 tidb_group_id = 2 [(google.api.field_behavior) = OPTIONAL];
}

message ListPrivateLinkConnectionsResponse {
  repeated PrivateLinkConnection private_link_connections = 1;
}

message DeletePrivateLinkConnectionRequest {
  string private_link_connection_id = 1 [(google.api.field_behavior) = REQUIRED];
}

message GetPrivateLinkConnectionRequest {
  string private_link_connection_id = 1 [(google.api.field_behavior) = REQUIRED];
}
