// Pluggable post-translation pipeline stages.
// IDs must match the step IDs used in MigrationFlow's initializeSteps.

export interface PipelinePlugin {
  readonly id: string;
  readonly name: string;
  readonly description: string;
  readonly defaultEnabled: boolean;
}

export const PIPELINE_PLUGINS: readonly PipelinePlugin[] = [
  {
    id: 'test-generation',
    name: 'Test Generation',
    description: 'Generates unit and integration test scaffolds for every converted module.',
    defaultEnabled: true,
  },
  {
    id: 'syntax-validation',
    name: 'Syntax Validation',
    description: 'Verifies that generated code compiles and passes a syntax check.',
    defaultEnabled: true,
  },
  {
    id: 'functional-validation',
    name: 'Functional Validation',
    description: 'Runs the generated test suite and checks behavioral parity with the source.',
    defaultEnabled: true,
  },
  {
    id: 'performance-analysis',
    name: 'Performance Analysis',
    description: 'Profiles runtime characteristics and flags regressions against the source baseline.',
    defaultEnabled: true,
  },
  {
    id: 'security-scan',
    name: 'Security Scan',
    description: 'Runs a static vulnerability analysis on the converted codebase.',
    defaultEnabled: true,
  },
  {
    id: 'documentation',
    name: 'Documentation Generation',
    description: 'Generates API docs and inline code documentation from the converted source.',
    defaultEnabled: true,
  },
] as const;

export const PLUGIN_IDS: ReadonlySet<string> = new Set(PIPELINE_PLUGINS.map(p => p.id));

/**
 * Returns the set of enabled plugin IDs from a project config.
 * Returns null when enabledPlugins is absent — backward compat means all plugins enabled.
 */
export function getEnabledPluginSet(cfg: Record<string, unknown>): Set<string> | null {
  if (!Array.isArray(cfg.enabledPlugins)) return null;
  return new Set((cfg.enabledPlugins as unknown[]).filter((x): x is string => typeof x === 'string'));
}

export function isPluginEnabled(id: string, enabledSet: Set<string> | null): boolean {
  return enabledSet === null || enabledSet.has(id);
}
