syntax = "proto3";

package oto.runner.v1;

option go_package = "github.com/toki/oto/services/core/oto;otopb";

message RunnerCapability {
  string name = 1;
  string version = 2;
}

message CommandCatalogSummary {
  repeated string command_types = 1;
}

message RegisterRunnerRequest {
  string enrollment_token = 1;
  string runner_id = 2;
  string alias = 3;
  string protocol_version = 4;
  RunnerCapability capability = 5;
  CommandCatalogSummary command_catalog = 6;
}

message RegisterRunnerResponse {
  bool accepted = 1;
  string reject_reason = 2;
  string runner_id = 3;
  string alias = 4;
  ProtocolError error = 5;
}

enum HeartbeatStatus {
  HEARTBEAT_STATUS_UNSPECIFIED = 0;
  HEARTBEAT_STATUS_HEALTHY = 1;
  HEARTBEAT_STATUS_UNHEALTHY = 2;
}

message HeartbeatRequest {
  string runner_id = 1;
  HeartbeatStatus status = 2;
}

message HeartbeatResponse {
  bool success = 1;
  string error_message = 2;
  ProtocolError error = 3;
}

message BootstrapCommandRequest {
  string runner_id = 1;
  string enrollment_token = 2;
  string target = 3;
}

message BootstrapCommandResponse {
  string bootstrap_command = 1;
}

message JobClaimRequest {
  string runner_id = 1;
  string job_id = 2;
  string execution_id = 3;
}

message JobClaimResponse {
  bool accepted = 1;
  string error_message = 2;
  string job_id = 3;
  string execution_id = 4;
  string state = 5;
  string runner_id = 6;
  RunRequest run_request = 7;
  ProtocolError error = 8;
}

message StepEventReport {
  int32 step_id = 1;
  int32 workflow_index = 2;
  string step_type = 3;
  string event = 4;
  string timestamp = 5;
  string command_id = 6;
  string command_type = 7;
  map<string, string> error = 8;
}

message ExecutionReportRequest {
  string runner_id = 1;
  string job_id = 2;
  string execution_id = 3;
  bool success = 4;
  int32 exit_code = 5;
  string message = 6;
  repeated StepEventReport step_events = 7;
}

message ExecutionReportResponse {
  bool accepted = 1;
  string error_message = 2;
  string job_id = 3;
  string execution_id = 4;
  string state = 5;
  string runner_id = 6;
  ProtocolError error = 7;
}

message LogAppendRequest {
  string runner_id = 1;
  string execution_id = 2;
  string line = 3;
}

message LogAppendResponse {
  bool accepted = 1;
  string error_message = 2;
  ProtocolError error = 3;
}

message ArtifactReportRequest {
  string runner_id = 1;
  string execution_id = 2;
  string name = 3;
  string path = 4;
}

message ArtifactReportResponse {
  bool accepted = 1;
  string error_message = 2;
  ProtocolError error = 3;
}

message ProtocolError {
  string code = 1;
  string message = 2;
  map<string, string> details = 3;
}

message RunRequest {
  string runner_id = 1;
  string job_id = 2;
  string execution_id = 3;
  string pipeline_yaml_path = 4; // Path to the pipeline YAML file to be executed
  string pipeline_yaml = 5;      // Inline content of the pipeline YAML if passed directly
  map<string, string> variables = 6; // Execution variables/parameters
  repeated string command_types = 7; // List of command types that are allowed or required, representing the capability/catalog limits
}

message CancelRunRequest {
  string runner_id = 1;
  string execution_id = 2;
  string reason = 3;
}

message CancelRunResponse {
  bool success = 1;
  string error_message = 2;
  ProtocolError error = 3;
}

message RunnerStatusRequest {
  string runner_id = 1;
}

message RunnerStatusResponse {
  string runner_id = 1;
  string status = 2;
  string current_execution_id = 3;
  ProtocolError error = 4;
}

message SelfUpdateRequest {
  string runner_id = 1;
  string version = 2;
  string download_url = 3;
}

message SelfUpdateResponse {
  bool success = 1;
  string error_message = 2;
  ProtocolError error = 3;
}
