/**
 * desktop_op 运行时的通用类型定义
 */

/** 窗口句柄 — 桌面适配器查询并传递给 runtime 使用 */
export interface WindowHandle {
  hwnd: number;
  pid: number;
  appName: string;
  title: string;
  bounds: { x: number; y: number; width: number; height: number };
  /** node-screenshots 的 Window 实例引用，截图调用方持有以便每次重新 enumerate */
  nsWindow: any;
}

/** 桌面任务通用 schema（应用无关） */
export interface DesktopTask {
  id: string;
  appId: string;                 // 'weixin' / 'excel' / ...
  target: any;                   // adapter 自定义，如 { conversation, channelId, roomName }
  actionType: string;            // 如 'send-text'
  params: any;                   // 如 { text, originalText }
  modelChannelId?: number;       // 不填则由 adapter / runtime 决定默认
  maxSteps?: number;             // 默认 8
  enqueuedAt: number;
}

/** 适配器 buildSteps 返回的最小动作单元 */
export type ActionStep =
  | { type: 'click'; x: number; y: number; thought?: string }
  | { type: 'hotkey'; key: string; thought?: string }
  | { type: 'clipboard-write'; text: string }
  | { type: 'type'; text: string; thought?: string }            // = clipboard-write + ctrl+v
  | { type: 'wait'; ms: number }
  | { type: 'mention'; wxid: string }                            // Layer 2 留口
  | { type: 'finished'; thought?: string }
  | { type: 'failed'; reason: string; thought?: string };

/** 任务执行结果 */
export interface TaskResult {
  ok: boolean;
  modelCalls: number;
  steps: number;
  durationMs: number;
}

/** 提供给 AppAdapter 的上下文（被 runtime 注入） */
export interface AdapterContext {
  window: WindowHandle;
  screenshot: any;  // Screenshooter — Task 6a 真正定义
  input: any;       // InputController — Task 6c
  vlm: any;         // VlmClient — Task 10
  parser: any;      // Parser — Task 3
  logger: any;
  task: DesktopTask;
  modelCalls: number;  // runtime 维护
}
