syntax = "proto3";

package tidb_mgmt_service.v1;

import "google/api/annotations.proto";
import "google/api/field_behavior.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "protoc-gen-openapiv2/options/annotations.proto";

/**
   All APIs here are for global control plane **internal** use only.
*/

option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
  swagger: "2.0"
  host: ""
  base_path: "/inner/mgmt/v1"
  info: {
    version: "v1"
    title: "Control Plane Internal API"
    description: "Control Plane Internal API."
  }
  schemes: HTTPS
};
service DataSynchronizationService {
  rpc CreateDataSynchronization(CreateDataSynchronizationRequest) returns (DataSynchronization) {
    option (google.api.http) = {
      post: "/dataSynchronizations"
      body: "*"
    };
  }
  rpc GetDataSynchronization(GetDataSynchronizationRequest) returns (DataSynchronization) {
    option (google.api.http) = {get: "/dataSynchronizations/{id}"};
  }
  rpc DeleteDataSynchronization(DeleteDataSynchronizationRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {delete: "/dataSynchronizations/{id}"};
  }
}

message DataSynchronization {
  // id is the unique identifier for the data synchronization.
  uint64 id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
  // source_cluster_id is the unique identifier for the source cluster.
  uint64 source_cluster_id = 2 [(google.api.field_behavior) = REQUIRED];
  // target_cluster_id is the unique identifier for the target cluster.
  // if the target cluster is not same project as the source cluster, the privatelink endpoint will be created between the source and target clusters.
  uint64 target_cluster_id = 3 [(google.api.field_behavior) = REQUIRED];
  // target_tidb_group_id is the target TiDB node group id within the target cluster.
  // If not set (0), the default TiDB node group will be used.
  uint64 target_tidb_group_id = 4 [(google.api.field_behavior) = OPTIONAL];
  // name is the name of the data synchronization, which is used to create changefeed.
  string name = 5 [(google.api.field_behavior) = REQUIRED];
  // description is the description of the data synchronization.
  string description = 6 [(google.api.field_behavior) = OPTIONAL];
  // state is the state of the data synchronization.
  State state = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
  // rcu is the resource capacity unit quota for the data synchronization.
  // default rcu 256
  uint64 rcu = 8 [(google.api.field_behavior) = OPTIONAL];
  // start_tso is the start tso for the changefeed.
  // if start_tso is not set or empty, the changefeed will be created from the current time (FROM_NOW mode).
  // if start_tso is set, the changefeed will be created from that specific tso (FROM_TSO mode).
  string start_tso = 9 [(google.api.field_behavior) = OPTIONAL];
  // create_time is the time when the data synchronization was created.
  google.protobuf.Timestamp create_time = 10 [(google.api.field_behavior) = OUTPUT_ONLY];
  // update_time is the time when the data synchronization was last updated.
  google.protobuf.Timestamp update_time = 11 [(google.api.field_behavior) = OUTPUT_ONLY];
  // target_cluster_username is the username to use when creating changefeed.
  // if empty, the control plane will use the cloud_admin as the username.
  string target_cluster_username = 12 [(google.api.field_behavior) = OPTIONAL];
  // target_cluster_password is the password to use when creating changefeed.
  // if the username is not empty, this password is required.
  string target_cluster_password = 13 [(google.api.field_behavior) = OPTIONAL];

  enum State {
    STATE_UNSPECIFIED = 0;
    PENDING = 1; // Operation is queued and waiting to start
    RUNNING = 2; // Operation is currently executing
    SUCCEEDED = 3; // Operation completed successfully
    FAILED = 4; // Operation failed
  }
}

message CreateDataSynchronizationRequest {
  DataSynchronization data_synchronization = 1 [(google.api.field_behavior) = REQUIRED];
  // If true, only validates the request and returns INVALID_ARGUMENT on failure,
  // without creating or starting the operation
  bool validate_only = 2 [(google.api.field_behavior) = OPTIONAL];
}

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

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