#!/usr/bin/env node
import fs from 'fs';
import assert from 'assert';

const files = [
  './.vl-code/workflows/parallel-codegen.json',
  './public/seed-workflows/parallel-codegen.json',
  './.vl-code/workflows/3-file-codegen.json',
  './public/seed-workflows/3-file-codegen.json',
  './.vl-code/workflows/meta-direct-codegen.json',
  './public/seed-workflows/meta-direct-codegen.json',
  './.vl-code/workflows/add-page.json',
  './public/seed-workflows/add-page.json',
];

function includesConstraint(workflow, needle) {
  const raw = JSON.stringify(workflow);
  return raw.includes(needle);
}

function main() {
  console.log('\n── Workflow Section Constraints ──');

  for (const file of files) {
    const workflow = JSON.parse(fs.readFileSync(file, 'utf-8'));
    assert.ok(includesConstraint(workflow, 'NEVER bind events directly on <For-*> nodes'), `${file} missing For event constraint`);
    assert.ok(includesConstraint(workflow, 'NEVER emit deprecated <StateStyle-*> trigger:\\"hover\\" blocks'), `${file} missing hover StateStyle constraint`);
    console.log(`PASS ${file}`);
  }

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

main();
