syntax = "proto3";

package common;

option go_package = "./;common";

service IngestionManager {
  rpc Action(stream IngestionMessage) returns (stream AdminMessage);
}

message IngestionMessage {
  string ingestor_id = 1;
  string message_type = 2;  // REGISTER, HEARTBEAT, TASK_RESULT, TASK_PROGRESS, PULL_REQUEST

  RegisterInfo register_info = 3;

  HeartbeatInfo heartbeat_info = 4;

  TaskResult task_result = 5;

  TaskProgress task_progress = 6;
}

message AdminMessage {
  string message_type = 1;  // TASK_ASSIGNMENT, ACK, PONG, RECONNECT
  TaskAssignment task_assignment = 2;
  AckInfo ack_info = 3;
  string error_message = 4;
}

message RegisterInfo {
  int32 max_concurrency = 1;
  repeated string supported_doc_types = 2;
  string version = 3;
  string name = 4;
}

message HeartbeatInfo {
  repeated TaskState task_states = 1;
  repeated string delete_task_ids = 2;
  float cpu_usage = 3; // percentage
  float vms_usage = 4; // absolute value
  float rss_usage = 5; // absolute value
  int64 process_id = 6; // pid
}

message TaskState {
  string task_id = 1;
  string status = 2;  // PENDING, RUNNING, COMPLETED, FAILED, CANCELLED
  string error_message = 3;
  int64 estimated_remaining_time_seconds = 4;
  string come_from = 5;
  int64 start_time = 6;
}

message TaskAssignment {
  string task_id = 1;
  string task_type = 2;
  string config = 3;
  string come_from = 4;
  string assigned_to = 5;
}

message TaskResult {
  string task_id = 1;
  string status = 2;  // COMPLETED, FAILED, CANCELLED
  string error_message = 3;
}

message TaskProgress {
  string task_id = 1;
  int32 progress = 2;
  string info = 3;
}

message AckInfo {
  string task_id = 1;
  bool success = 2;
  string message = 3;
}