import fs from 'fs';

function assert(condition, message) {
  if (!condition) throw new Error(message);
}

const cases = [
  ['./.vl-code/workflows/parallel-codegen.json', ['Loop_Services', 'Loop_Components', 'Loop_Sections', 'Loop_Apps']],
  ['./public/seed-workflows/parallel-codegen.json', ['Loop_Services', 'Loop_Components', 'Loop_Sections', 'Loop_Apps']],
  ['./.vl-code/workflows/meta-direct-codegen.json', ['Loop_Services', 'Loop_Components', 'Loop_Sections', 'Loop_Apps']],
  ['./public/seed-workflows/meta-direct-codegen.json', ['Loop_Services', 'Loop_Components', 'Loop_Sections', 'Loop_Apps']],
  ['./.vl-code/workflows/3-file-codegen.json', ['Loop_Components', 'Loop_ServiceDomains', 'Loop_Sections', 'Loop_Apps']],
  ['./public/seed-workflows/3-file-codegen.json', ['Loop_Components', 'Loop_ServiceDomains', 'Loop_Sections', 'Loop_Apps']],
  ['./.vl-code/workflows/6-file-codegen.json', ['Loop_GenVS', 'Loop_GenCP', 'Loop_GenSC', 'Loop_GenVX']],
  ['./public/seed-workflows/6-file-codegen.json', ['Loop_GenVS', 'Loop_GenCP', 'Loop_GenSC', 'Loop_GenVX']],
  ['./.vl-code/workflows/9-file-codegen.json', ['Loop_GenServiceDomains', 'Loop_GenComponents', 'Loop_GenSections', 'Loop_GenApps']],
  ['./public/seed-workflows/9-file-codegen.json', ['Loop_GenServiceDomains', 'Loop_GenComponents', 'Loop_GenSections', 'Loop_GenApps']],
];

console.log('\n── Workflow Parallel Fanout ──');

for (const [filePath, stepIds] of cases) {
  const workflow = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
  for (const stepId of stepIds) {
    const step = workflow.steps.find(item => item.id === stepId);
    assert(step, `${filePath}: missing step ${stepId}`);
    assert(step.mode === 'parallel', `${filePath}: ${stepId} should be parallel, got ${step.mode}`);
    console.log(`PASS ${filePath} -> ${stepId}=${step.mode}`);
  }
}

console.log('PASS test-workflow-section-sequencing.js');
