syntax = "proto3";

package global.dedicated.v1;

import "google/api/field_behavior.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

service PrivateLinkServiceMigrationService {
  rpc CreatePrivateLinkServiceMigration(CreatePrivateLinkServiceMigrationRequest) returns (PrivateLinkServiceMigration) {}
  rpc GetPrivateLinkServiceMigration(GetPrivateLinkServiceMigrationRequest) returns (PrivateLinkServiceMigration) {}
  rpc ListPrivateLinkServiceMigrations(ListPrivateLinkServiceMigrationsRequest) returns (ListPrivateLinkServiceMigrationsResponse) {}
  rpc CancelPrivateLinkServiceMigration(CancelPrivateLinkServiceMigrationRequest) returns (google.protobuf.Empty) {}
}

message PrivateLinkServiceMigration {
  uint64 id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
  uint64 source_cluster_id = 2 [(google.api.field_behavior) = REQUIRED];
  uint64 target_cluster_id = 3 [(google.api.field_behavior) = REQUIRED];
  repeated MigrationTidbGroup migration_tidb_groups = 4 [(google.api.field_behavior) = REQUIRED];
  RunMode run_mode = 5 [(google.api.field_behavior) = OPTIONAL];
  State state = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
  string message = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
  MigrationPlan migration_plan = 8 [(google.api.field_behavior) = OPTIONAL];
  uint64 organization_id = 9 [(google.api.field_behavior) = OUTPUT_ONLY];
  uint64 project_id = 10 [(google.api.field_behavior) = OUTPUT_ONLY];
  google.protobuf.Timestamp create_time = 100 [(google.api.field_behavior) = OUTPUT_ONLY];
  google.protobuf.Timestamp update_time = 101 [(google.api.field_behavior) = OUTPUT_ONLY];
  optional google.protobuf.Timestamp delete_time = 102 [(google.api.field_behavior) = OUTPUT_ONLY];

  /**
   * MigrationTidbGroup represents a pair of TiDB groups to be migrated.
   */
  message MigrationTidbGroup {
    uint64 source_tidb_group_id = 1 [(google.api.field_behavior) = REQUIRED];
    uint64 target_tidb_group_id = 2 [(google.api.field_behavior) = REQUIRED];
    State state = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
    string message = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
    google.protobuf.Timestamp start_time = 5 [(google.api.field_behavior) = OUTPUT_ONLY];
    google.protobuf.Timestamp complete_time = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
  }
  message MigrationPlan {
    bool disable_recreate_private_link_service_for_source_tidb_group = 1 [(google.api.field_behavior) = OPTIONAL];
    optional int32 timeout_seconds = 2 [(google.api.field_behavior) = OPTIONAL];
  }

  enum RunMode {
    RUN_MODE_UNSPECIFIED = 0;
    PARALLEL = 1;
    SEQUENTIAL = 2;
  }

  enum State {
    STATE_UNSPECIFIED = 0;
    PENDING = 1;
    RUNNING = 2;
    SUCCEEDED = 3;
    FAILED = 4;
    CANCELLED = 5;
  }
}

message CreatePrivateLinkServiceMigrationRequest {
  PrivateLinkServiceMigration migration = 1 [(google.api.field_behavior) = REQUIRED];

  bool validate_only = 2 [(google.api.field_behavior) = OPTIONAL];
}

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

message ListPrivateLinkServiceMigrationsRequest {
  uint64 source_cluster_id = 1 [(google.api.field_behavior) = OPTIONAL];
  uint64 target_cluster_id = 2 [(google.api.field_behavior) = OPTIONAL];
  uint64 organization_id = 3 [(google.api.field_behavior) = OPTIONAL];
  uint64 project_id = 4 [(google.api.field_behavior) = OPTIONAL];
  repeated PrivateLinkServiceMigration.State states = 5 [(google.api.field_behavior) = OPTIONAL];
  google.protobuf.Timestamp create_time_from = 6 [(google.api.field_behavior) = OPTIONAL];
  google.protobuf.Timestamp create_time_to = 7 [(google.api.field_behavior) = OPTIONAL];
  uint32 page_size = 100 [(google.api.field_behavior) = OPTIONAL];
  uint32 page = 101 [(google.api.field_behavior) = OPTIONAL];
}

message ListPrivateLinkServiceMigrationsResponse {
  repeated PrivateLinkServiceMigration migrations = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
}

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