/** Flow registry. Han skills as Spine configs + the bespoke code-review pipeline. */
import type { Flow, Spine } from '../types.js';
import { buildSpineFlow } from '../spine.js';

import { research } from './research.js';
import { investigate } from './investigate.js';
import { architecturalAnalysis } from './architectural-analysis.js';
import { securityReview } from './security-review.js';
import {
  gapAnalysis,
  projectDiscovery,
  projectDocumentation,
  testPlanning,
  dataReview,
  devopsReview,
  issueTriage,
} from './discovery.js';
import {
  planFeature,
  planImplementation,
  planPhasedBuild,
  planWorkItems,
  iterativePlanReview,
} from './planning.js';
import { adr, codingStandard, runbook, tdd, stakeholderSummary } from './authoring.js';
import { codeReview } from './code-review.js';
import { parallelResearch } from './parallel-research.js';

const spines: Spine[] = [
  // analysis / research
  research,
  investigate,
  architecturalAnalysis,
  securityReview,
  gapAnalysis,
  dataReview,
  devopsReview,
  issueTriage,
  // discovery / docs / tests
  projectDiscovery,
  projectDocumentation,
  testPlanning,
  // planning (best-effort one-pass)
  planFeature,
  planImplementation,
  planPhasedBuild,
  planWorkItems,
  iterativePlanReview,
  // authoring / reporting (best-effort one-pass)
  adr,
  codingStandard,
  runbook,
  tdd,
  stakeholderSummary,
];

const bespoke: Flow[] = [codeReview, parallelResearch];

const ALL: Flow[] = [...spines.map(buildSpineFlow), ...bespoke];

export const FLOWS: Record<string, Flow> = Object.fromEntries(ALL.map((f) => [f.name, f]));
export const FLOW_NAMES: string[] = ALL.map((f) => f.name);

export function describeFlows(): string {
  return ALL.map((f) => `  ${f.name.padEnd(24)} ${f.description}`).join('\n');
}

export function getFlow(name: string): Flow | undefined {
  return FLOWS[name];
}
