/**
 * Messages describing sessions and associated requests and responses.
 */
syntax = "proto3";

package armonik.api.grpc.v1.sessions;

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "objects.proto";
import "session_status.proto";
import "sessions_fields.proto";
import "sessions_filters.proto";
import "sort_direction.proto";

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

/**
 * A raw session object.
 */
message SessionRaw {
  string session_id = 1; /** The session ID. */
  session_status.SessionStatus status = 2; /** The session status. */
  bool client_submission = 8; /** Whether clients can submit tasks in the session. */
  bool worker_submission = 9; /** Whether workers can submit tasks in the session. */
  repeated string partition_ids = 3; /** The partition IDs. */
  TaskOptions options = 4; /** The task options. In fact, these are used as default value in child tasks. */

  google.protobuf.Timestamp created_at = 5; /** The creation date. */
  google.protobuf.Timestamp cancelled_at = 6; /** The cancellation date. Only set when status is 'cancelled'. */
  google.protobuf.Timestamp closed_at = 12; /** The closure date. Only set when status is 'closed'. */
  google.protobuf.Timestamp purged_at = 10; /** The purge date. Only set when status is 'purged'. */
  google.protobuf.Timestamp deleted_at = 11; /** The deletion date. Only set when status is 'deleted'. */
  google.protobuf.Duration duration = 7; /** The duration. Only set when status is 'cancelled' and 'closed'. */
}

/**
 * Request to list sessions.
 *
 * Use pagination, filtering and sorting.
 */
message ListSessionsRequest {
  int32 page = 1; /** The page number. Start at 0. */
  int32 page_size = 2; /** The page size. */

  Filters filters = 3; /** The filters. */

  /**
   * Represents the sort object.
   */
  message Sort {
    SessionField field = 1; /** The field to sort on. */
    sort_direction.SortDirection direction = 2; /** The sort direction. */
  }

  /** The sort.
   *
   * Must be set for every request.
   */
  Sort sort = 4;

  /**
   * Flag to tell if server must return task options in summary sessions
   */
  bool with_task_options = 5;
}

/**
 * Response to list sessions.
 *
 * Use pagination, filtering and sorting from the request.
 * Return a list of summary sessions.
 */
message ListSessionsResponse {
  repeated SessionRaw sessions = 1; /** The list of sessions. */

  int32 page = 2; /** The current page. Start at 0. */
  int32 page_size = 3; /** The page size. */
  int32 total = 4; /** The total number of sessions. */
}

/**
 * Request for getting a single session.
 */
message GetSessionRequest {
  string session_id = 1; /** The session ID. */
}

/**
 * Response for getting a single session.
 *
 * Return a raw session.
 */
message GetSessionResponse {
  SessionRaw session = 1; /** The session. */
}

/**
 * Request for cancelling a single session.
 */
message CancelSessionRequest {
  string session_id = 1; /** The session ID. */
}

/**
 * Response for cancelling a single session.
 *
 * Return a raw session.
 */
message CancelSessionResponse {
  SessionRaw session = 1; /** The session. */
}

/**
 * Request for creating session.
 */
message CreateSessionRequest {
  TaskOptions default_task_option = 1; /** Default tasks options for tasks in the session */
  repeated string partition_ids = 2; /** List of partitions allowed during the session */
}

/*
	Reply after session creation.
	We have this reply in case of success.
	When the session creation is not successful, there is an rpc exception.
*/
message CreateSessionReply {
  string session_id = 1; /** Session id of the created session if successful */
}

/**
 * Request for pausing a single session.
 */
message PauseSessionRequest {
  string session_id = 1; /** The session ID. */
}

/**
 * Response for pausing a single session.
 *
 * Return a raw session.
 */
message PauseSessionResponse {
  SessionRaw session = 1; /** The session. */
}

/**
 * Request for resuming a single session.
 */
message ResumeSessionRequest {
  string session_id = 1; /** The session ID. */
}

/**
 * Response for resuming a single session.
 *
 * Return a raw session.
 */
message ResumeSessionResponse {
  SessionRaw session = 1; /** The session. */
}

/**
 * Request for closing a single session.
 */
message CloseSessionRequest {
  string session_id = 1; /** The session ID. */
}

/**
 * Response for closing a single session.
 *
 * Return a raw session.
 */
message CloseSessionResponse {
  SessionRaw session = 1; /** The session. */
}

/**
 * Request for purging a single session.
 */
message PurgeSessionRequest {
  string session_id = 1; /** The session ID. */
}

/**
 * Response for purging a single session.
 *
 * Return a raw session.
 */
message PurgeSessionResponse {
  SessionRaw session = 1; /** The session. */
}

/**
 * Request for deleting a single session.
 */
message DeleteSessionRequest {
  string session_id = 1; /** The session ID. */
}

/**
 * Response for deleting a single session.
 *
 * Return a raw session.
 */
message DeleteSessionResponse {
  SessionRaw session = 1; /** The session. */
}

/**
 * Request for stopping new tasks submissions from clients or workers in the given session.
 */
message StopSubmissionRequest {
  string session_id = 1; /** The session ID. */
  bool client = 2; /** Whether to stop client submission. */
  bool worker = 3; /** Whether to stop worker submission. */
}

/**
 * Response for stopping new tasks submissions from clients or workers in the given session.
 *
 * Return a raw session.
 */
message StopSubmissionResponse {
  SessionRaw session = 1; /** The session. */
}
