syntax = "proto3";

package global.nextgen.v1;

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

service ByocVpcPeeringService {
  rpc ListVpcPeerings(ListVpcPeeringsRequest) returns (ListVpcPeeringsResponse) {}
  rpc GetVpcPeering(GetVpcPeeringRequest) returns (VpcPeering) {}
  rpc GetVpcPeeringAllowlistSetting(GetVpcPeeringAllowlistSettingRequest) returns (VpcPeeringAllowlistSetting) {}
  rpc UpdateVpcPeeringAllowlistSetting(UpdateVpcPeeringAllowlistSettingRequest) returns (VpcPeeringAllowlistSetting) {}
}

message VpcPeering {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  string id = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
  common.v1.CloudProvider.Name cloud_provider_id = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
  State state = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
  common.v1.Region.Name tidb_cloud_region_id = 5 [(google.api.field_behavior) = OUTPUT_ONLY];
  common.v1.Region.Name customer_region_id = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
  string tidb_cloud_account_id = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
  string customer_account_id = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
  string tidb_cloud_vpc_id = 9 [(google.api.field_behavior) = OUTPUT_ONLY];
  string customer_vpc_id = 10 [(google.api.field_behavior) = OUTPUT_ONLY];
  string tidb_cloud_vpc_cidr = 11 [(google.api.field_behavior) = OUTPUT_ONLY];
  string customer_vpc_cidr = 12 [(google.api.field_behavior) = OUTPUT_ONLY];

  enum State {
    STATE_UNSPECIFIED = 0;
    PENDING = 1;
    FAILED = 2;
    ACTIVE = 3;
  }
}

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

message ListVpcPeeringsResponse {
  repeated VpcPeering vpc_peerings = 1;
}

message GetVpcPeeringRequest {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  string vpc_peering_id = 2 [(google.api.field_behavior) = REQUIRED];
}

message VpcPeeringAllowlistSetting {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  repeated Endpoint.IpAddress ip_access_list = 2 [(google.api.field_behavior) = OPTIONAL];
}

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

message UpdateVpcPeeringAllowlistSettingRequest {
  uint64 cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  message ReplaceVpcPeeringAllowlist {
    repeated Endpoint.IpAddress ip_access_list = 1 [(google.api.field_behavior) = OPTIONAL];
  }
  oneof change {
    ReplaceVpcPeeringAllowlist replace = 2;
    google.protobuf.Empty clear = 3;
  }
}
