syntax = "proto3";

package tidb_mgmt_service.v1;

import "global/common/v1/resources.proto";
import "global/dedicated/v1/resources.proto";
import "global/dedicated/v1/services.proto";
import "google/api/annotations.proto";
import "google/api/field_behavior.proto";
import "google/protobuf/empty.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 SpuService {
  rpc CreateComputeMu(CreateComputeMuRequest) returns (ComputeMu) {
    option (google.api.http) = {
      post: "/computeMus"
      body: "compute_mu"
    };
  }

  rpc DeleteComputeMu(DeleteComputeMuRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {delete: "/computeMus/{id}"};
  }

  rpc GetComputeMu(GetComputeMuRequest) returns (ComputeMu) {
    option (google.api.http) = {get: "/computeMus/{id}"};
  }

  rpc ListComputeMus(ListComputeMusRequest) returns (ListComputeMusResponse) {
    option (google.api.http) = {get: "/computeMus"};
  }

  rpc CreateStorageMu(CreateStorageMuRequest) returns (StorageMu) {
    option (google.api.http) = {
      post: "/storageMus"
      body: "storage_mu"
    };
  }

  rpc DeleteStorageMu(DeleteStorageMuRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {delete: "/storageMus/{id}"};
  }

  rpc GetStorageMu(GetStorageMuRequest) returns (StorageMu) {
    option (google.api.http) = {get: "/storageMus/{id}"};
  }

  rpc ListStorageMus(ListStorageMusRequest) returns (ListStorageMusResponse) {
    option (google.api.http) = {get: "/storageMus"};
  }

  rpc CreateSku(CreateSkuRequest) returns (Sku) {
    option (google.api.http) = {
      post: "/skus"
      body: "sku"
    };
  }

  rpc UpdateSku(UpdateSkuRequest) returns (Sku) {
    option (google.api.http) = {
      patch: "/skus/{sku.id}"
      body: "sku"
    };
  }

  rpc DeleteSku(DeleteSkuRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {delete: "/skus/{id}"};
  }

  rpc GetSku(GetSkuRequest) returns (Sku) {
    option (google.api.http) = {get: "/skus/{id}"};
  }

  rpc ListSkus(ListSkusRequest) returns (ListSkusResponse) {
    option (google.api.http) = {get: "/skus"};
  }

  rpc CreateSpu(CreateSpuRequest) returns (Spu) {
    option (google.api.http) = {
      post: "/spus"
      body: "spu"
    };
  }

  rpc UpdateSpu(UpdateSpuRequest) returns (Spu) {
    option (google.api.http) = {
      patch: "/spus/{spu.id}"
      body: "spu"
    };
  }

  rpc DeleteSpu(DeleteSpuRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {delete: "/spus/{id}"};
  }

  rpc GetSpu(GetSpuRequest) returns (Spu) {
    option (google.api.http) = {get: "/spus/{id}"};
  }

  rpc ListSpus(ListSpusRequest) returns (ListSpusResponse) {
    option (google.api.http) = {get: "/spus"};
  }
}

// Compute Material Unit simply contains information of compute resource directly from 3rd-party cloud providers.
message ComputeMu {
  uint64 id = 1 [
    (google.api.field_behavior) = IDENTIFIER,
    (google.api.field_behavior) = OUTPUT_ONLY
  ];

  global.common.v1.CloudProvider.Name cloud_provider = 2 [(google.api.field_behavior) = REQUIRED];

  string instance_type = 4 [(google.api.field_behavior) = REQUIRED];

  int32 cpu_core = 5 [(google.api.field_behavior) = REQUIRED];
  int32 memory_gi = 6 [(google.api.field_behavior) = REQUIRED];
  global.dedicated.v1.InstanceMu.CpuArch cpu_arch = 7 [(google.api.field_behavior) = REQUIRED];
  global.dedicated.v1.InstanceMu.CpuGeneration cpu_generation = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Storage Material Unit simply contains information of storage resource directly from 3rd-party cloud providers.
message StorageMu {
  uint64 id = 1 [
    (google.api.field_behavior) = IDENTIFIER,
    (google.api.field_behavior) = OUTPUT_ONLY
  ];

  global.common.v1.CloudProvider.Name cloud_provider = 2 [(google.api.field_behavior) = REQUIRED];

  global.dedicated.v1.StorageMu.VolumeType volume_type = 4 [(google.api.field_behavior) = REQUIRED];
}

// Stock Keeping Unit.
message Sku {
  uint64 id = 1 [
    (google.api.field_behavior) = IDENTIFIER,
    (google.api.field_behavior) = OUTPUT_ONLY
  ];

  // A SKU belongs to a specific SPU.
  uint64 spu_id = 2 [(google.api.field_behavior) = REQUIRED];
  string spu_key = 16 [(google.api.field_behavior) = OUTPUT_ONLY];
  string spu_name = 17 [(google.api.field_behavior) = OUTPUT_ONLY];
  string spu_display_name = 18 [(google.api.field_behavior) = OUTPUT_ONLY];
  string spu_version = 20 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Human readable SKU name.
  string key = 3 [(google.api.field_behavior) = REQUIRED];

  global.common.v1.CloudProvider.Name cloud_provider = 4 [(google.api.field_behavior) = REQUIRED];

  global.dedicated.v1.ComponentType component_type = 5 [(google.api.field_behavior) = REQUIRED];

  uint64 instance_mu_id = 6 [(google.api.field_behavior) = REQUIRED];
  global.dedicated.v1.InstanceMu.CpuArch cpu_arch = 12 [(google.api.field_behavior) = OUTPUT_ONLY];
  string instance_type = 13 [(google.api.field_behavior) = OUTPUT_ONLY];
  global.dedicated.v1.InstanceMu.CpuGeneration cpu_generation = 19 [(google.api.field_behavior) = OUTPUT_ONLY];
  int32 cpu_core = 14 [(google.api.field_behavior) = OUTPUT_ONLY];
  int32 memory_gi = 15 [(google.api.field_behavior) = OUTPUT_ONLY];

  int32 default_node_count = 7 [(google.api.field_behavior) = REQUIRED];

  repeated global.dedicated.v1.Sku.Condition conditions = 8 [(google.api.field_behavior) = OPTIONAL];

  int32 priority = 9 [(google.api.field_behavior) = OPTIONAL];

  global.dedicated.v1.Sku.Storage data_storage = 10 [(google.api.field_behavior) = OPTIONAL];
  global.dedicated.v1.Sku.Storage raftlog_storage = 11 [(google.api.field_behavior) = OPTIONAL];
}

// Standard Product Unit.
message Spu {
  uint64 id = 1 [
    (google.api.field_behavior) = IDENTIFIER,
    (google.api.field_behavior) = OUTPUT_ONLY
  ];

  // example: 2C8G:DEPLOY_TYPE_DEDICATED:COMPONENT_TYPE_TIKV
  string key = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
  // example: 2 vCPU, 8 GiB (Beta)
  string display_name = 3 [(google.api.field_behavior) = REQUIRED];
  // example: 2C8G
  string name = 4 [(google.api.field_behavior) = REQUIRED];
  string version = 14 [(google.api.field_behavior) = REQUIRED];

  global.dedicated.v1.ComponentType component_type = 5 [(google.api.field_behavior) = REQUIRED];

  int32 cpu_core = 6 [(google.api.field_behavior) = REQUIRED];
  int32 memory_size_gi = 7 [(google.api.field_behavior) = REQUIRED];

  repeated global.dedicated.v1.Spu.Mapping mappings = 13 [(google.api.field_behavior) = OPTIONAL];
}

message CreateComputeMuRequest {
  ComputeMu compute_mu = 1 [(google.api.field_behavior) = REQUIRED];
}

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

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

message ListComputeMusRequest {
  global.common.v1.CloudProvider.Name cloud_provider = 1 [(google.api.field_behavior) = REQUIRED];
  repeated global.dedicated.v1.InstanceMu.CpuArch cpu_archs = 2 [(google.api.field_behavior) = OPTIONAL];
}

message ListComputeMusResponse {
  repeated ComputeMu compute_mus = 1;
}

message CreateStorageMuRequest {
  StorageMu storage_mu = 1 [(google.api.field_behavior) = REQUIRED];
}

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

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

message ListStorageMusRequest {
  global.common.v1.CloudProvider.Name cloud_provider = 1 [(google.api.field_behavior) = REQUIRED];
  repeated global.dedicated.v1.StorageMu.VolumeType volume_types = 2 [(google.api.field_behavior) = OPTIONAL];
}

message ListStorageMusResponse {
  repeated StorageMu storage_mus = 1;
}

message CreateSkuRequest {
  Sku sku = 1 [(google.api.field_behavior) = REQUIRED];
}

message UpdateSkuRequest {
  global.dedicated.v1.BatchUpsertSkusRequest.Update sku = 1 [(google.api.field_behavior) = REQUIRED];
}

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

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

message ListSkusRequest {
  // Deprecated: use `cloud_providers` instead.
  global.common.v1.CloudProvider.Name cloud_provider = 1 [
    (google.api.field_behavior) = OPTIONAL,
    deprecated = true
  ];
  repeated global.common.v1.CloudProvider.Name cloud_providers = 3 [(google.api.field_behavior) = OPTIONAL];
  repeated global.dedicated.v1.ComponentType component_types = 2 [(google.api.field_behavior) = OPTIONAL];
}

message ListSkusResponse {
  repeated Sku skus = 1;
}

message CreateSpuRequest {
  Spu spu = 1 [(google.api.field_behavior) = REQUIRED];
}

message UpdateSpuRequest {
  global.dedicated.v1.BatchUpsertSpusRequest.Update spu = 1 [(google.api.field_behavior) = REQUIRED];
}

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

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

message ListSpusRequest {
  // Deprecated: use `component_types` instead.
  global.dedicated.v1.ComponentType component_type = 1 [
    (google.api.field_behavior) = OPTIONAL,
    deprecated = true
  ];
  repeated global.dedicated.v1.ComponentType component_types = 3 [(google.api.field_behavior) = OPTIONAL];
  repeated string versions = 2 [(google.api.field_behavior) = OPTIONAL];
}

message ListSpusResponse {
  repeated Spu spus = 1;
}
