/**
 * The Hearth — Agent Hierarchy API
 * GET /api/dark-factory/agents
 *
 * Returns the standalone agent hierarchy, quality gate configuration,
 * and agent role descriptions. Fully standalone — no FF dependency.
 */

import { NextResponse } from 'next/server';
import { getHierarchy, getAgentList, QUALITY_GATE, PREAMBLE_DIRECTIVES } from '@/lib/dark-factory/agents/hierarchy';
import { LANGUAGE_OPTIONS, DATABASE_OPTIONS } from '@/lib/dark-factory/types/generation-options';

export const dynamic = 'force-dynamic';

export async function GET() {
  const hierarchy = getHierarchy();
  const agents = getAgentList();

  return NextResponse.json({
    pipeline: 'standalone',
    hierarchy: {
      root: {
        id: hierarchy.root.id,
        name: hierarchy.root.name,
        title: hierarchy.root.title,
        description: hierarchy.root.description,
      },
      agents: agents.map((a) => ({
        id: a.id,
        name: a.name,
        title: a.title,
        description: a.description,
        responsibilities: a.responsibilities,
        parent: a.parent,
        children: a.children,
      })),
    },
    qualityGate: QUALITY_GATE,
    preambleDirectives: PREAMBLE_DIRECTIVES.map((d) => ({
      id: d.id,
      category: d.category,
      title: d.title,
      directive: d.directive,
      appliesTo: d.appliesTo,
    })),
    supportedLanguages: LANGUAGE_OPTIONS.map((l) => ({
      id: l.id,
      label: l.label,
      framework: l.framework,
      icon: l.icon,
    })),
    supportedDatabases: DATABASE_OPTIONS.map((d) => ({
      id: d.id,
      label: d.label,
      icon: d.icon,
    })),
  });
}
