syntax = "proto3";
package client_server_contract;

import "common_types.proto";

message ServerToClientMsg {
  oneof message {
    RenderMsg render = 1;
    UnblockInputThreadMsg unblock_input_thread = 2;
    ExitMsg exit = 3;
    ConnectedMsg connected = 4;
    LogMsg log = 5;
    LogErrorMsg log_error = 6;
    SwitchSessionMsg switch_session = 7;
    UnblockCliPipeInputMsg unblock_cli_pipe_input = 8;
    CliPipeOutputMsg cli_pipe_output = 9;
    QueryTerminalSizeMsg query_terminal_size = 10;
    StartWebServerMsg start_web_server = 11;
    RenamedSessionMsg renamed_session = 12;
    ConfigFileUpdatedMsg config_file_updated = 13;
    PaneRenderUpdateMsg pane_render_update = 14;
    SubscribedPaneClosedMsg subscribed_pane_closed = 15;
    ForwardQueryToHostMsg forward_query_to_host = 16;
    SetSoftKeyboardMsg set_soft_keyboard = 17;
    EmitNestedSessionFrameMsg emit_nested_session_frame = 18;
    MobileStateMsg mobile_state = 19;
  }
}

message RenderMsg {
  string content = 1;
}

message UnblockInputThreadMsg {
  // Empty message
}

message ExitMsg {
  ExitReason exit_reason = 1;
  optional string payload = 2;
}

message ConnectedMsg {
  // Empty message
}

message LogMsg {
  repeated string lines = 1;
}

message LogErrorMsg {
  repeated string lines = 1;
}

message SwitchSessionMsg {
  ConnectToSession connect_to_session = 1;
}

message UnblockCliPipeInputMsg {
  string pipe_name = 1;
}

message CliPipeOutputMsg {
  string pipe_name = 1;
  string output = 2;
}

message QueryTerminalSizeMsg {
  // Empty message
}

message StartWebServerMsg {
  // Empty message
}

message RenamedSessionMsg {
  string name = 1;
}

message ConfigFileUpdatedMsg {
  // Empty message
}

message PaneRenderUpdateMsg {
  PaneId pane_id = 1;
  repeated string viewport = 2;
  repeated string scrollback = 3;
  bool has_scrollback = 4;
  bool is_initial = 5;
}

message SubscribedPaneClosedMsg {
  PaneId pane_id = 1;
}

message ForwardQueryToHostMsg {
  uint32 token = 1;
  bytes query_bytes = 2;
  bool resolve_async = 3;
}

message SetSoftKeyboardMsg {
  bool on = 1;
}

message EmitNestedSessionFrameMsg {
  bytes payload_bytes = 1;
}

message MobileSizeMsg {
  uint32 cols = 1;
  uint32 rows = 2;
}

message MobileActivePaneMsg {
  uint32 pane_id = 1;
  bool is_plugin = 2;
  uint32 tab_position = 3;
}

message MobileTabMsg {
  uint32 position = 1;
  string name = 2;
  bool active = 3;
}

message MobilePaneMsg {
  uint32 tab_position = 1;
  uint32 pane_id = 2;
  bool is_plugin = 3;
  string title = 4;
  bool is_floating = 5;
  uint64 last_activity_secs_ago = 6;
}

message MobileSessionMsg {
  string name = 1;
  bool web_clients_allowed = 2;
  uint32 tab_count = 3;
  uint32 pane_count = 4;
  uint32 connected_clients = 5;
  uint64 creation_secs_ago = 6;
}

message MobileRenderPrefsMsg {
  bool single_pane = 1;
  bool fit = 2;
  bool active_pane_is_fullscreen = 3;
}

message MobileStateMsg {
  string session_name = 1;
  uint64 now_secs = 2;
  bool is_welcome_screen = 3;
  bool desktop_client_connected = 4;
  optional MobileSizeMsg desktop_size = 5;
  optional MobileActivePaneMsg active_pane = 6;
  repeated MobileTabMsg tabs = 7;
  repeated MobilePaneMsg panes = 8;
  repeated MobileSessionMsg sessions = 9;
  MobileRenderPrefsMsg render_prefs = 10;
}
