#!/usr/bin/env node
/** Validates thin app/experience routes — max 25 lines, import from @/modules/experience */
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

const APP = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "app", "experience");
const MAX_LINES = 25;
let errors = [];

function walk(dir) {
  for (const ent of fs.readdirSync(dir, { withFileTypes: true })) {
    const p = path.join(dir, ent.name);
    if (ent.isDirectory()) walk(p);
    else if (ent.name === "page.tsx") check(p);
  }
}

function check(file) {
  const rel = path.relative(APP, file);
  const content = fs.readFileSync(file, "utf8");
  const lines = content.split("\n").length;
  if (lines > MAX_LINES) errors.push(`${rel}: ${lines} lines (max ${MAX_LINES})`);
  if (!content.includes("@/modules/experience/")) {
    errors.push(`${rel}: must import from @/modules/experience/`);
  }
}

if (fs.existsSync(APP)) walk(APP);
else errors.push("app/experience not found");

if (errors.length) {
  console.error("Experience route validation failed:\n" + errors.map((e) => "  - " + e).join("\n"));
  process.exit(1);
}
console.log("Experience routes OK");
