syntax = "proto3";

package global.dedicated.v1;

import "google/api/field_behavior.proto";

// DataPlatformCompatService provide TiDB cluster and vpc information for DataPlatform.
service DataPlatformCompatService {
  rpc GetCompatCluster(GetCompatClusterRequest) returns (CompatCluster) {}

  rpc GetCompatNetwork(GetCompatNetworkRequest) returns (CompatNetwork) {}

  rpc GetCompatProvider(GetCompatProviderRequest) returns (CompatProvider) {}
}

// All fields are OUTPUT_ONLY unless otherwise specified.
message CompatCluster {
  uint64 id = 1;
  string provider = 2;

  string region = 3;
  string cluster_status = 4;
  uint64 organization_id = 5 [(google.api.field_behavior) = REQUIRED];
  uint64 project_id = 6 [(google.api.field_behavior) = REQUIRED];
  NodeRole node_role = 7;
  ClusterTopology cluster_topology = 8;

  message NodeRole {
    string cloud_iam_identity = 1; // aws role or gcp serviceaccount
    string external_id = 2;
  }

  message ClusterTopology {
    Component tidb = 1;
    Component tikv = 2;
    Component pd = 3;
    Component tiflash = 4;
    Component tiproxy = 5;

    message Component {
      int32 replicas = 1;
      string instance_type = 2;
    }
  }
}

// All fields are OUTPUT_ONLY unless otherwise specified.
message CompatNetwork {
  string k8s_name = 1;
  string k8s_version = 2;
  string k8s_ca = 3;
  string k8s_endpoint = 4;
  bool k8s_ready = 5;
  string vpc_id = 6;
  string node_role = 7;
  oneof info {
    Aws aws = 8;
    Gcp gcp = 9;
    Azure azure = 16;
  }
  string proxy_base_url = 10;
  IAM iam = 11;
  string cidr = 12;
  string dataflow_agent_url = 13;
  repeated string external_ips = 14;
  string tenant_id = 15;

  message Aws {
    repeated NodeSubnet node_subnets = 1;
    repeated NodeSubnet private_subnets = 2;
    string security_group_id = 3;
    repeated NodeSubnet secondary_node_subnets = 4;

    message NodeSubnet {
      string subnet_id = 1;
      string availability_zone = 2;
      string availability_zone_id = 3;
    }
  }

  message Gcp {
    repeated string node_zones = 1;
    repeated string node_subnets = 2;
    string psc_subnet = 3; // private service connect NAT subnet
    string admin_node_sa = 4;
  }

  message Azure {
    repeated string node_zones = 1;
    repeated string node_subnet_ids = 2;
    repeated string pod_subnet_ids = 3;
    string resource_group = 4;
  }

  message IAM {
    string account_id = 1;
    string external_id = 2;
  }
}

// All fields are OUTPUT_ONLY unless otherwise specified.
message CompatProvider {
  string name = 1 [(google.api.field_behavior) = REQUIRED];
  repeated CompatRegion regions = 2;

  message CompatRegion {
    string name = 1;
    repeated string zones = 2;
  }
}

message GetCompatClusterRequest {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  bool show_deleted = 2 [(google.api.field_behavior) = OPTIONAL];
}

message GetCompatNetworkRequest {
  uint64 project_id = 1 [(google.api.field_behavior) = REQUIRED];
  string provider_name = 2 [(google.api.field_behavior) = REQUIRED];
  string region_name = 3 [(google.api.field_behavior) = REQUIRED];
}

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