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

import { IChatTurn } from "../interfaces/chat-turn.ts";
import { IDroneRegistration } from "../interfaces/drone-registration.ts";

import { GadgetComponent } from "../lib/component.ts";
import { GadgetLogLevel } from "../lib/log.ts";

import { WorkspaceMode } from "./ide.ts";

export type ProcessWorkOrderCallback = (
  success: boolean,
  message?: string,
) => void;
export type ProcessWorkOrderMessage = (
  registration: IDroneRegistration,
  turn: IChatTurn,
  cb: ProcessWorkOrderCallback,
) => void;

export type LogMessage = (
  timestamp: Date,
  component: GadgetComponent,
  level: GadgetLogLevel,
  message: string,
  metadata?: unknown,
) => void;

export type StatusMessage = (content: string) => void;

export type ThinkingMessage = (content: string) => void;

export type ResponseMessage = (content: string) => void;

export type ToolCallMessage = (
  callId: string,
  name: string,
  params: string,
  response: string,
) => void;

export type WorkOrderCompleteMessage = (
  workOrderId: string,
  success: boolean,
  message?: string,
) => void;

export type RequestCrashRecoveryMessage = (data: {
  workspaceId: string;
  turnId: string;
  chatSessionId: string;
}) => void;

export type CrashRecoveryResponseMessage = (data: {
  turnId: string;
  action: "discard" | "retry";
  retryDelay?: number;
}) => void;

export type RequestTerminationMessage = (
  cb: (success: boolean) => void,
) => void;

export type WorkspaceModeChangedMessage = (mode: WorkspaceMode) => void;
