syntax = "proto3";

package ctrl.prompt.v1;

import "google/protobuf/empty.proto";

service PromptService {
  rpc WatchEvents(WatchEventsRequest) returns (stream PromptEvent);
  rpc Respond(RespondRequest) returns (google.protobuf.Empty);
  rpc Abort(AbortRequest) returns (google.protobuf.Empty);
  rpc SetLocale(SetLocaleRequest) returns (SetLocaleResponse);
  rpc ProducerSession(stream ProducerCommand) returns (stream ProducerEvent);
}

enum PromptSeverity {
  PROMPT_SEVERITY_UNSPECIFIED = 0;
  PROMPT_SEVERITY_INFO = 1;
  PROMPT_SEVERITY_SUCCESS = 2;
  PROMPT_SEVERITY_WARNING = 3;
  PROMPT_SEVERITY_ERROR = 4;
}

enum PromptActionIntent {
  PROMPT_ACTION_INTENT_UNSPECIFIED = 0;
  PROMPT_ACTION_INTENT_PRIMARY = 1;
  PROMPT_ACTION_INTENT_SECONDARY = 2;
  PROMPT_ACTION_INTENT_DANGER = 3;
}

enum PromptDialogSize {
  PROMPT_DIALOG_SIZE_UNSPECIFIED = 0;
  PROMPT_DIALOG_SIZE_SM = 1;
  PROMPT_DIALOG_SIZE_MD = 2;
  PROMPT_DIALOG_SIZE_LG = 3;
}

enum PromptResolutionStatus {
  PROMPT_RESOLUTION_STATUS_UNSPECIFIED = 0;
  PROMPT_RESOLUTION_STATUS_ANSWERED = 1;
  PROMPT_RESOLUTION_STATUS_CANCELLED = 2;
  PROMPT_RESOLUTION_STATUS_ABORTED = 3;
}

enum PromptErrorCode {
  PROMPT_ERROR_CODE_UNSPECIFIED = 0;
  PROMPT_ERROR_CODE_INVALID_PROMPT = 1;
  PROMPT_ERROR_CODE_QUEUE_FULL = 2;
  PROMPT_ERROR_CODE_NOT_OWNER = 3;
  PROMPT_ERROR_CODE_STALE_PROMPT = 4;
  PROMPT_ERROR_CODE_INVALID_ACTION = 5;
  PROMPT_ERROR_CODE_INVALID_SESSION = 6;
}

message PromptDetail {
  string label = 1;
  string value = 2;
}

message PromptAction {
  string id = 1;
  string label = 2;
  PromptActionIntent intent = 3;
}

message ActivePrompt {
  string prompt_id = 1;
  string source_id = 2;
  string request_id = 3;
  string title = 4;
  string message = 5;
  PromptSeverity severity = 6;
  repeated PromptDetail details = 7;
  repeated PromptAction actions = 8;
  bool allow_abort = 9;
  PromptDialogSize size = 10;
}

message PromptState {
  uint64 revision = 1;
  optional ActivePrompt active = 2;
  uint32 queued_count = 3;
  string effective_locale = 4;
}

message PromptFault {
  string code = 1;
  string message = 2;
}

message WatchEventsRequest {}

message PromptEvent {
  oneof event {
    PromptState state = 1;
    PromptFault fault = 2;
  }
}

message RespondRequest {
  string prompt_id = 1;
  string action_id = 2;
}

message AbortRequest {
  string prompt_id = 1;
}

message SetLocaleRequest {
  string locale = 1;
}

message SetLocaleResponse {
  string effective_locale = 1;
}

message OpenProducer {
  string source_id = 1;
}

message SubmitConfigured {
  string request_id = 1;
  string prompt_name = 2;
}

message CancelPrompt {
  string prompt_id = 1;
}

message AcknowledgeResult {
  string prompt_id = 1;
}

message ProducerCommand {
  string command_id = 1;
  oneof command {
    OpenProducer open = 2;
    SubmitConfigured submit_configured = 3;
    CancelPrompt cancel = 4;
    AcknowledgeResult acknowledge_result = 5;
  }
}

message ProducerSuccess {
  string command_id = 1;
  string prompt_id = 2;
}

message ProducerFailure {
  string command_id = 1;
  PromptErrorCode code = 2;
  string message = 3;
}

message PromptResolved {
  string prompt_id = 1;
  PromptResolutionStatus status = 2;
  string action_id = 3;
}

message ProducerEvent {
  oneof event {
    ProducerSuccess success = 1;
    ProducerFailure failure = 2;
    PromptResolved resolved = 3;
  }
}
