// src/messages/socket.ts
// Copyright (C) 2026 Rob Colbert <rob.colbert@openplatform.us>
// Licensed under the Apache License, Version 2.0

import {
  StatusMessage,
  ProcessWorkOrderMessage,
  ResponseMessage,
  ThinkingMessage,
  ToolCallMessage,
  WorkOrderCompleteMessage,
  RequestCrashRecoveryMessage,
  CrashRecoveryResponseMessage,
  RequestTerminationMessage,
  WorkspaceModeChangedMessage,
} from "./drone.ts";
import {
  ReleaseSessionLockMessage,
  RequestSessionLockMessage,
  RequestWorkspaceModeMessage,
  SessionHeartbeatMessage,
  SubmitPromptMessage,
} from "./ide.ts";

/*
There are two different kinds of clients that connect to the gadget-code:web
Socket.IO server:

1. The gadget-code:ide (ReactJS front-end)
2. The gadget-drone work order runner (NodeJS headless process)

gadget-code:ide sends Socket.IO messages to gadget-code:web, which then routes
them to the appropriate gadget-drone socket.

gadget-drone sends messages to gadget-code:web intending for them to be routed
to the appropriate gadget-code:ide socket.

This architecture lets the IDE run under User control in any browser anywhere,
and serve as a remote control surface for one or more gadget-drone processes
running work orders on projects in chat sessions.
*/

export interface ClientToServerEvents {
  /*
   * gadget-code:ide => gadget-code:web
   */

  requestSessionLock: RequestSessionLockMessage;
  requestWorkspaceMode: RequestWorkspaceModeMessage;
  submitPrompt: SubmitPromptMessage;
  releaseSessionLock: ReleaseSessionLockMessage;
  sessionHeartbeat: SessionHeartbeatMessage;

  /*
   * gadget-drone => gadget-code:web
   */

  status: StatusMessage;
  thinking: ThinkingMessage;
  response: ResponseMessage;
  toolCall: ToolCallMessage;
  workOrderComplete: WorkOrderCompleteMessage;
  requestCrashRecovery: RequestCrashRecoveryMessage;
  requestTermination: RequestTerminationMessage;
  workspaceModeChanged: WorkspaceModeChangedMessage;
}

export interface ServerToClientEvents {
  /*
   * gadget-code:web => gadget-drone
   */

  requestSessionLock: RequestSessionLockMessage;
  requestWorkspaceMode: RequestWorkspaceModeMessage;
  releaseSessionLock: ReleaseSessionLockMessage;
  sessionHeartbeat: SessionHeartbeatMessage;
  processWorkOrder: ProcessWorkOrderMessage;
  crashRecoveryResponse: CrashRecoveryResponseMessage;
  requestTermination: RequestTerminationMessage;

  /*
   * gadget-code:web => gadget-code:ide
   */

  status: StatusMessage;
  thinking: ThinkingMessage;
  response: ResponseMessage;
  toolCall: ToolCallMessage;
  workOrderComplete: WorkOrderCompleteMessage;
  workspaceModeChanged: WorkspaceModeChangedMessage;
}

export interface SocketData {
  /* no data defined */
}
