/**
 * Static slash-command hints per harness (interactive TUI / agent session).
 * Live ACP `available_commands_update` merges on top during dispatch.
 */
import type { AgentCommand } from './provider-types.js';

const CLAUDE_COMMANDS: AgentCommand[] = [
  { name: 'help', description: 'Show available slash commands' },
  { name: 'clear', description: 'Clear conversation history' },
  { name: 'compact', description: 'Compact context window' },
  { name: 'cost', description: 'Show session cost' },
  { name: 'memory', description: 'Manage project memory' },
  { name: 'model', description: 'Switch model' },
  { name: 'permissions', description: 'View or change permission mode' },
  { name: 'review', description: 'Review current changes' },
  { name: 'status', description: 'Show session status' },
  { name: 'vim', description: 'Toggle vim-style input' },
];

const OPENCODE_COMMANDS: AgentCommand[] = [
  { name: 'help', description: 'Show available commands' },
  { name: 'new', description: 'Start a new session' },
  { name: 'models', description: 'List or switch models' },
  { name: 'agents', description: 'List or switch agents' },
  { name: 'compact', description: 'Compact context' },
  { name: 'share', description: 'Share session' },
  { name: 'export', description: 'Export session' },
];

const GOOSE_COMMANDS: AgentCommand[] = [
  { name: 'help', description: 'Show available commands' },
  { name: 'clear', description: 'Clear conversation' },
  { name: 'compact', description: 'Compact context' },
  { name: 'exit', description: 'Exit session' },
];

const QWEN_COMMANDS: AgentCommand[] = [
  { name: 'help', description: 'Show available slash commands' },
  { name: 'clear', description: 'Clear conversation' },
  { name: 'memory', description: 'Manage memory' },
  { name: 'hooks', description: 'Manage hooks' },
  { name: 'review', description: 'Review changes' },
];

const REASONIX_COMMANDS: AgentCommand[] = [
  { name: 'help', description: 'Show available slash commands' },
  { name: 'clear', description: 'Clear conversation history' },
  { name: 'compact', description: 'Compact context window' },
  { name: 'effort', description: 'Change reasoning effort' },
  { name: 'hooks', description: 'Manage hooks' },
  { name: 'mcp', description: 'Manage MCP servers' },
  { name: 'memory', description: 'Manage project memory' },
  { name: 'model', description: 'Switch model' },
  { name: 'skill', description: 'Manage skills' },
];

/** boocode harness uses /api/skills — merged on the frontend. */
export const PROVIDER_COMMANDS: Record<string, AgentCommand[]> = {
  claude: CLAUDE_COMMANDS,
  opencode: OPENCODE_COMMANDS,
  goose: GOOSE_COMMANDS,
  qwen: QWEN_COMMANDS,
  reasonix: REASONIX_COMMANDS,
  boocode: [],
};

export function getManifestCommands(provider: string): AgentCommand[] {
  return PROVIDER_COMMANDS[provider] ?? [];
}

export function mergeCommands(...lists: AgentCommand[][]): AgentCommand[] {
  const byName = new Map<string, AgentCommand>();
  for (const list of lists) {
    for (const cmd of list) {
      byName.set(cmd.name, cmd);
    }
  }
  return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
}
