syntax = "proto3";

package tidb_cloud_open_api.zero.v1beta1;

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

option go_package = "tidb_cloud_open_api/zero/v1beta1";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
  swagger: "2.0"
  host: "zero.tidbapi.com"
  base_path: "/v1beta1"
  info: {
    version: "v1beta1"
    title: "TiDB Cloud Zero API"
    description: ""
  }
  schemes: HTTPS
  consumes: "application/json"
  produces: "application/json"

  // Define the common error responses.
  responses: {
    key: "400"
    value: {
      description: "A request field is invalid."
      schema: {
        json_schema: {ref: ".google.rpc.Status"}
      }
    }
  }
  responses: {
    key: "429"
    value: {
      description: "You have exceeded the rate limit."
      schema: {
        json_schema: {ref: ".google.rpc.Status"}
      }
    }
  }
  responses: {
    key: "500"
    value: {
      description: "Internal server error."
      schema: {
        json_schema: {ref: ".google.rpc.Status"}
      }
    }
  }
};

service ZeroInstanceService {
  rpc AllocateZeroInstance(AllocateZeroInstanceRequest) returns (AllocateZeroInstanceResponse) {
    option (google.api.http) = {
      post: "/instances"
      body: "*"
    };
  }
  rpc GetZeroInstance(GetZeroInstanceRequest) returns (GetZeroInstanceResponse) {
    option (google.api.http) = {get: "/instances/{id}"};
  }
}

message AllocateZeroInstanceRequest {
  string tag = 4 [(google.api.field_behavior) = OPTIONAL];
}

message ZeroInstance {
  string id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
  Connection connection = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
  string connection_string = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  ClaimInfo claim_info = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  google.protobuf.Timestamp expires_at = 100 [(google.api.field_behavior) = OUTPUT_ONLY];

  message Connection {
    string host = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
    int32 port = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
    string username = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
    string password = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  message ClaimInfo {
    string zero_id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
    string claim_url = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
  }
}

message AllocateZeroInstanceResponse {
  ZeroInstance instance = 1;
}

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

message GetZeroInstanceResponse {
  ZeroInstance instance = 1;
}
