syntax = "proto3";

package armonik.api.grpc.v1.events;

import "result_status.proto";
import "results_filters.proto";
import "task_status.proto";
import "tasks_filters.proto";

option csharp_namespace = "ArmoniK.Api.gRPC.V1.Events";

/**
 * Represents the events that can be returned in the EventSubscriptionResponse
 */
enum EventsEnum {
  EVENTS_ENUM_UNSPECIFIED = 0; /** Unspecified */
  EVENTS_ENUM_NEW_TASK = 1; /** New task */
  EVENTS_ENUM_TASK_STATUS_UPDATE = 2; /** Task status update */
  EVENTS_ENUM_NEW_RESULT = 3; /** New restult */
  EVENTS_ENUM_RESULT_STATUS_UPDATE = 4; /** Result status update */
  EVENTS_ENUM_RESULT_OWNER_UPDATE = 5; /** Result owner update */
}

/**
 * Request to subscribe to the event stream.
 */
message EventSubscriptionRequest {
  string session_id = 1; /** Id of the session that will be used to subscribe events for. **/
  tasks.Filters tasks_filters = 2; /** Filter for task related events. */
  results.Filters results_filters = 3; /** Filter for result related events. */
  repeated EventsEnum returned_events = 4; /** Filter the type of events to return. Empty means all. */
}

/**
 * Response containing the update event.
 */
message EventSubscriptionResponse {
  string session_id = 1; /** Id of the session that will be used to subscribe events for. **/

  /**
   * Represents an update to the status of a task.
   */
  message TaskStatusUpdate {
    string task_id = 10; /** The task id. **/
    task_status.TaskStatus status = 11; /** The task status. **/
  }

  /**
   * Represents an update to the status of a result.
   */
  message ResultStatusUpdate {
    string result_id = 20; /** The result id. **/
    result_status.ResultStatus status = 21; /** The result status. **/
  }

  /**
   * Represents an update to the owner task id of a result.
   */
  message ResultOwnerUpdate {
    string result_id = 30; /** The result id. **/
    string previous_owner_id = 31; /** The previous owner id. **/
    string current_owner_id = 32; /** The current owner id. **/
  }

  /**
   * Represents the submission of a new task in ArmoniK.
   */
  message NewTask {
    string task_id = 40; /** The task id. **/
    string payload_id = 41; /** The payload id. **/
    string origin_task_id = 42; /** The task id before retry. **/
    task_status.TaskStatus status = 43; /** The task status. **/
    repeated string expected_output_keys = 44; /** The keys of the expected outputs **/
    repeated string data_dependencies = 45; /** The keys of the data dependencies. **/
    repeated string retry_of_ids = 46; /** The list of retried tasks from the first retry to the current. **/
    repeated string parent_task_ids = 47; /** The parent task IDs. A tasks can be a child of another task. **/
  }

  /**
   * Represents the submission of a new result in ArmoniK.
   */
  message NewResult {
    string result_id = 50; /** The result id. **/
    string owner_id = 51; /** The owner task id. **/
    result_status.ResultStatus status = 52; /** The result status. **/
  }

  /**
   * Represents an event update. Only one update will be sent per message.
   */
  oneof update {
    TaskStatusUpdate task_status_update = 2; /** An update to the status of a task. **/
    ResultStatusUpdate result_status_update = 3; /** An update to the status of a result. **/
    ResultOwnerUpdate result_owner_update = 4; /** An update to the owner of a result. **/
    NewTask new_task = 5; /** A new task in ArmoniK. **/
    NewResult new_result = 6; /** A new result in ArmoniK. **/
  }
}
