syntax = "proto3";

import "google/protobuf/timestamp.proto";
import "yandex/cloud/api/operation.proto";


service TankJobService {
  rpc Get (GetTankJobRequest) returns (TankJob);
  rpc List (ListTankJobsRequest) returns (ListTankJobsResponse);
  rpc Create (CreateTankJobRequest) returns (operation.Operation);   // should return Operation
  rpc Update (UpdateTankJobRequest) returns (operation.Operation);  // should return Operation
  rpc Delete (DeleteTankJobRequest) returns (operation.Operation);  // should return Operation
  rpc UploadFile (stream Chunk) returns (UploadResponse);
}

// TestService requests and responses
message GetTankJobRequest {};
message ListTankJobsRequest {};
message UpdateTankJobRequest {};
message CreateTankJobRequest {};
message DeleteTankJobRequest {};
message ListTankJobsResponse {};
message UploadResponse {

  enum UploadStatusCode {
    UNKNOWN = 0;
    OK = 1;
    FAILED= 2;
  }

  string message = 1;
  UploadStatusCode upload_status = 2;
}


// An instance of TankJob
message TankJob {

  enum Status {
  STATUS_UNSPECIFIED = 0;
  CREATED = 1;
  INITIATED = 2;
  PREPARING = 3;
  RUNNING = 4;
  FINISHING = 5;
  FINISHED = 6;
  POST_PROCESS = 7;
  NOT_FOUND = 8;
  }

  // Test id
  string id = 1;

  // Folder id that test belongs to
  // ???: should test belong to any folder
  string folder_id = 2;

  // Timestamp when the test is created
  // May be not the same with test start timestamp
  google.protobuf.Timestamp created_at = 3;

  // Test name
  string name = 4;

  // Test description
  string description = 5;

  // Test labels, format key:value, 64 pairs max for the test
  map<string, string> labels = 6;

  // Test status
  Status status = 7;

  // Timestamp when test started
  google.protobuf.Timestamp started_at = 8;

  // Timestamp when test finished
  google.protobuf.Timestamp finished_at = 9;

  // Person who initiated test
  string author = 10;

  // TODO Link to Ammo
  // Ammo that was used in this test
  //  TankAmmo tank_ammo = 11;

  // Number of ammo loops
  int32 ammo_loops = 12;

  // TODO Link to TankInstance
  // TankInstance that was used in this test
  //  TankInstance tank_instance = 13;

  // TODO Link to Target -- VM
  // VM that was used as a target
  // Instance instance_id = 14;

  // TODO ConfigInfo -- link to Config
  // Resulting config
  // TankConfig config_info = 15;

  // TODO ConfigInitial -- link to Config
  // Initial TankConfig
  // TankConfig config_initial = 16;

}


// Chunk for file streaming
message Chunk {

  enum FileType {
    CONFIG = 0;
    AMMO = 1;
  }

  bytes chunk_content = 1;
  string   tank_job = 2;
  FileType file_type = 3;
}

// YandexTank config
message TankConfig {}

// YandexTank ammo
message TankAmmo {}
