syntax = "proto3";

package tidb_mgmt_service.v1;

import "google/api/annotations.proto";
import "google/api/field_behavior.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
};

// FsRegionService manages the fs region records owned by the mgmt service.
// The fs system has no global service; these internal APIs are the write path
// for the region data served by the fs OpenAPI.
service FsRegionService {
  rpc CreateFsRegion(CreateFsRegionRequest) returns (FsRegion) {
    option (google.api.http) = {
      post: "/fs_regions"
      body: "*"
    };
  }

  rpc UpdateFsRegion(UpdateFsRegionRequest) returns (FsRegion) {
    option (google.api.http) = {
      patch: "/fs_regions/{region_id}"
      body: "*"
    };
  }

  // ListFsRegions returns all fs regions, including INACTIVE ones.
  rpc ListFsRegions(ListFsRegionsRequest) returns (ListFsRegionsResponse) {
    option (google.api.http) = {get: "/fs_regions"};
  }

  // GetFsRegion returns the fs region regardless of its status.
  rpc GetFsRegion(GetFsRegionRequest) returns (FsRegion) {
    option (google.api.http) = {get: "/fs_regions/{region_id}"};
  }
}

message FsRegion {
  // The ID of the region, in the format of `{cloud_provider}-{region_code}`. For example, `aws-us-west-2`.
  string region_id = 1;

  // A human-readable name for the region. For example, `Oregon (us-west-2)`.
  string display_name = 2;

  // The endpoint address of the fs regional server in this region.
  string service_address = 3;

  // The lifecycle state of the region: `ACTIVE` or `INACTIVE`. Empty means `ACTIVE` on create.
  string status = 4;
}

message CreateFsRegionRequest {
  FsRegion region = 1 [(google.api.field_behavior) = REQUIRED];
}

message ListFsRegionsRequest {}

message ListFsRegionsResponse {
  repeated FsRegion regions = 1;
}

message GetFsRegionRequest {
  // The ID of the region, in the format of `{cloud_provider}-{region_code}`. For example, `aws-us-west-2`.
  string region_id = 1 [(google.api.field_behavior) = REQUIRED];
}

message UpdateFsRegionRequest {
  // The ID of the region to update, in the format of `{cloud_provider}-{region_code}`. For example, `aws-us-west-2`.
  string region_id = 1 [(google.api.field_behavior) = REQUIRED];

  // Only `display_name`, `service_address`, and `status` are updatable. Empty fields are left unchanged.
  FsRegion region = 2 [(google.api.field_behavior) = REQUIRED];
}
