syntax = "proto3";

package yandex.cloud.loadtesting.v1.tank_instance;

import "google/protobuf/timestamp.proto";

service TankInstanceService {

    // Returns the specified TankInstance resource.
    // To get the list of available TankInstance resources, make a [List] request.
    rpc Get (GetTankInstanceRequest) returns (TankInstance);

    // Retrieves the list of TankInstance resources in the specified folder.
    rpc List (ListTankInstancesRequest) returns (ListTankInstancesResponse);

  // Creates a TankInstance in the specified folder.
  // Method starts an asynchronous operation that can be cancelled while it is in progress.
  rpc Create (CreateTankInstanceRequest) returns (TankInstance);

  // Updates the specified instance
    // TODO: return operation.Operation instead of Instance

  rpc Update (UpdateTankInstanceRequest) returns (TankInstance);

  // Deletes the specified instance.
      // TODO: return operation.Operation instead of Instance

  rpc Delete (DeleteTankInstanceRequest) returns (TankInstance);

}


// An instance with YandexTank
message TankInstance {
  enum Status {
    STATUS_UNSPECIFIED = 0;

    // Instance is waiting for resources to be allocated.
    PROVISIONING = 1;

    // Instance is running normally.
    RUNNING = 2;

    // Instance is being stopped.
    STOPPING = 3;

    // Instance stopped.
    STOPPED = 4;

    // Instance is being started.
    STARTING = 5;

    // Instance is being restarted.
    RESTARTING = 6;

    // Instance is being updated.
    UPDATING = 7;

    // Instance encountered a problem and cannot operate.
    ERROR = 8;

    // Instance crashed and will be restarted automatically.
    CRASHED = 9;

    // Instance is being deleted.
    DELETING = 10;
  }

  // Tank instance id
  string id = 1;

  // Folder id that tank belongs to
  string folder_id = 2;

  google.protobuf.Timestamp created_at = 3;

  // Tank instance name. 1-63 characters long
  string name = 4;

  // Tank instance description,0-256 characters long
  string description = 5;

  // Tank instance labels, format key:value. 64 pairs maximum for the resource
  map<string, string> labels = 6;

  // Zone id where tank instance resides
  string zone_id = 7;

  // Information about software tank version and platform configuration
  string tank_platform = 8;

  // Tank instance status
  Status status = 10;

  // TODO: there should be some instance info, may be nested compute.Instance
  // Instance instance = 9;

  // TODO: YandexTank information, may be nested loadtesting.YandexTank

}

// Pre-built setup for YankInstance
message InstanceSpec {}


// TankInstanceService requests and responses
message GetTankInstanceRequest {
    // TankInstance resource ID to return.
    string tankinstance_id = 1;
}

message ListTankInstancesRequest {
    // ID of the Folder to list tank instances in.
  // To get the folder ID, use a [yandex.cloud.resourcemanager.v1.FolderService.List] request.
  string folder_id = 1;

  // The maximum number of results per page to return. If the number of available
  // results is larger than [page_size],
  // the service returns a [ListTankInstancesResponse.next_page_token]
  // that can be used to get the next page of results in subsequent list requests.
  int64 page_size = 2;

  // Page token. To get the next page of results,
  // set [page_token] to the [ListInstancesResponse.next_page_token]
  // returned by a previous list request.
  string page_token = 3;

  // A filter expression that filters resources listed in the response.
  // The expression must specify:
  // 1. The field name.
  // 2. An operator. Can be either `=` or `!=` for single values, `IN` or `NOT IN` for lists of values.
  // 3. The value. Must be 3-63 characters long and match the regular expression `^[a-z]([-a-z0-9]{,61}[a-z0-9])?$`.
  string filter = 4 ;
}

message ListTankInstancesResponse {
    // List of Instance resources.
  repeated TankInstance tankinstances = 1;

  // This token allows you to get the next page of results for list requests. If the number of results
  // is larger than [ListTankInstancesRequest.page_size], use
  // the [next_page_token] as the value
  // for the [ListTankInstancesRequest.page_token] query parameter
  // in the next list request. Each subsequent list request will have its own
  // [next_page_token] to continue paging through the results.
  string next_page_token = 2;
}

message CreateTankInstanceRequest {
    // ID of the folder to create an instance in.
  // To get the folder ID, use a [yandex.cloud.resourcemanager.v1.FolderService.List] request.
  string folder_id = 1;

  // Name of the tank instance.
  string name = 2;

  // Description of the tank instance.
  string description = 3;

  // Resource labels as `key:value` pairs.
  map<string, string> labels = 4;

  // ID of the availability zone where the instance resides.
  // To get a list of available zones, use the [yandex.cloud.compute.v1.ZoneService.List] request
  string zone_id = 5;

  // ID of the hardware platform configuration for the TankInstance.
  // This field affects the available values in [resources_spec] field.
  //
  // Platforms allows you to create various types of instances: with a large amount of memory,
  // with a large number of cores, with a burstable performance.
  string tank_platform = 6;

  // The metadata `key:value` pairs that will be assigned to this instance. This includes custom metadata and predefined keys.
  // The total size of all keys and values must be less than 512 KB.
  //
  // Values are free-form strings, and only have meaning as interpreted by the programs which configure the instance.
  // The values must be 256 KB or less.
  //
  // For example, you may use the metadata in order to provide your public SSH key to the instance.
  map<string, string> metadata = 8;

  // TODO: Add config for TankInstance
  // Instance configuration for Tank Instance?
    InstanceSpec instance_spec = 9;

}

message UpdateTankInstanceRequest {}

message DeleteTankInstanceRequest {}
