import { handle as handleSpec } from './spec.js';
import { handle as handleAdo } from './ado.js';
import { handle as handleQa } from './qa.js';
import { handle as handlePrototype } from './prototype.js';
import { handle as handleConfig } from './config.js';
import { handle as handleIntake } from './intake.js';
import { handle as handleMisc } from './misc.js';

export async function dispatch(req, res, url, ctx) {
  const p = url.pathname;
  if (p.startsWith('/api/ado/') || p.startsWith('/api/wi/')) return handleAdo(req, res, url, ctx);
  if (p.startsWith('/api/qa/')) return handleQa(req, res, url, ctx);
  if (p.startsWith('/api/prototype/')) return handlePrototype(req, res, url, ctx);
  if (p.startsWith('/api/intake/')) return handleIntake(req, res, url, ctx);
  if (p === '/api/gchat-config' || p === '/api/ado-config' || p.startsWith('/api/mcp/') || p.startsWith('/api/usage/')) return handleConfig(req, res, url, ctx);
  if (p === '/api/plan' || p === '/api/resolve-spec' || p === '/api/spec-file' || p === '/api/steps' || p === '/api/specs' || p === '/api/files-exist') return handleSpec(req, res, url, ctx);
  return handleMisc(req, res, url, ctx);
}
