/**
 * Agent types — shared interfaces for multi-agent support.
 */

export type AgentId = string; // 'claude' | 'codex' | 'aider' | custom

export interface AgentCapabilities {
  supportsResume: boolean;          // -c / --resume (continue session)
  supportsStreamJson: boolean;      // structured output parsing
  supportsModel: boolean;           // --model flag
  supportsSkipPermissions: boolean; // --dangerously-skip-permissions or equivalent
  hasSessionFiles: boolean;         // on-disk session files (JSONL etc.)
  requiresTTY: boolean;             // needs pseudo-terminal (e.g., codex)
}

export interface AgentConfig {
  id: AgentId;
  name: string;             // display name: "Claude Code", "OpenAI Codex", "Aider"
  path: string;             // binary path
  enabled: boolean;
  type: 'claude-code' | 'generic'; // adapter type
  flags?: string[];         // extra CLI flags
  capabilities: AgentCapabilities;
  version?: string;
  skipPermissionsFlag?: string; // e.g., "--dangerously-skip-permissions" (claude), "--dangerously-bypass-approvals-and-sandbox" (codex), "--yes" (aider)
  // Profile fields
  base?: string;             // base agent ID — makes this a profile
  isProfile?: boolean;       // true if this is a profile (not a base agent)
  backendType?: 'cli' | 'api'; // 'api' for API profiles
  provider?: string;         // API provider (anthropic, google, openai, grok)
  model?: string;            // model override for profiles
  apiKey?: string;           // per-profile API key
  env?: Record<string, string>; // env vars injected on spawn
  cliType?: 'claude-code' | 'codex' | 'aider' | 'generic'; // CLI tool type
}

export interface AgentSpawnOptions {
  projectPath: string;
  prompt: string;
  model?: string;
  conversationId?: string;  // for resume
  skipPermissions?: boolean;
  outputFormat?: 'stream-json' | 'json' | 'text';
  extraFlags?: string[];
  /**
   * Extra text appended to the agent's system prompt for this run.
   * Maps to `--append-system-prompt` on Claude Code. Adapters that
   * don't support the concept ignore it.
   */
  appendSystemPrompt?: string;
}

export interface AgentSpawnResult {
  cmd: string;
  args: string[];
  env?: Record<string, string>;
}

export interface AgentAdapter {
  id: AgentId;
  config: AgentConfig;

  /** Build spawn command + args for non-interactive task execution */
  buildTaskSpawn(opts: AgentSpawnOptions): AgentSpawnResult;

  /** Build the terminal command string (e.g., "cd /path && claude -c") */
  buildTerminalCommand(opts: {
    projectPath: string;
    resume?: boolean;
    sessionId?: string;
    skipPermissions?: boolean;
  }): string;

  /** Parse a line of output into normalized events (for stream-json agents) */
  parseOutputLine?(line: string): any[];
}
