/**
 * WebSocket message types for SSH Console.
 *
 * Binary frames carry raw PTY bytes (server→client output, client→server input).
 * Text frames carry JSON control messages keyed by `type`.
 */

export type SessionCloseReason =
  | 'idle_timeout'
  | 'duration_cap'
  | 'host_disconnect'
  | 'maintenance'
  | 'admin_kill'
  | 'connection_change'
  | 'session_cap_evict'
  | 'worker_shutdown'
  | 'access_revoked';

export type AttachMessage = {
  type: 'attach';
  acting_user_id: string;
  can_write: boolean;
  connection_id: string;
  cols: number;
  rows: number;
};

export type ReplayBeginMessage = { type: 'replay_begin'; bytes: number };
export type ReplayEndMessage = { type: 'replay_end' };

export type ResizeMessage = {
  type: 'resize';
  cols: number;
  rows: number;
};

export type NoticeSeverity = 'info' | 'warn' | 'error';
export type NoticeMessage = {
  type: 'notice';
  severity: NoticeSeverity;
  msg: string;
};

export type CloseMessage = {
  type: 'close';
  reason: SessionCloseReason;
};

export type ServerTextMessage =
  | AttachMessage
  | ReplayBeginMessage
  | ReplayEndMessage
  | NoticeMessage
  | CloseMessage;

export type ClientTextMessage = ResizeMessage;

export type AnyTextMessage = ServerTextMessage | ClientTextMessage;
