const ClaudeAdapter = require('./claude');
const CodexAdapter = require('./codex');

/**
 * Tool adapter registry.
 *
 * Adding a new adapter (Cursor, Aider, Cline, …):
 *   1. Create `src/utils/tool-adapters/<name>.js` exporting a class with
 *      the same shape as ClaudeAdapter/CodexAdapter.
 *   2. Add it to the REGISTRY below.
 *   3. (Optional) Implement `static detect(cwd)` so `baldart configure`
 *      can autodetect when the user already has the tool installed.
 *
 * Adapters do NOT translate skill content — they just declare WHERE the
 * tool reads from. The same source file under `.framework/framework/.claude/skills/`
 * is symlinked into each enabled tool's expected directory.
 */
const REGISTRY = {
  claude: ClaudeAdapter,
  codex:  CodexAdapter
};

function listAdapters() {
  return Object.keys(REGISTRY);
}

function getAdapter(name, cwd) {
  const Cls = REGISTRY[name];
  if (!Cls) throw new Error(`Unknown tool adapter: ${name}. Available: ${listAdapters().join(', ')}`);
  return new Cls(cwd);
}

/**
 * Returns the list of tool names that should be enabled by default for
 * a fresh install. Always includes `claude` (the framework's primary
 * target). Includes `codex` if the user appears to have it installed.
 */
function defaultEnabled(cwd) {
  const enabled = ['claude'];
  if (CodexAdapter.detect(cwd)) enabled.push('codex');
  return enabled;
}

module.exports = { REGISTRY, listAdapters, getAdapter, defaultEnabled };
