/**
 * Writes the three blank import templates to ./exports (SPEC 34).
 *
 * The running application serves the same files from /api/templates/<kind>;
 * this script is for handing them out offline.
 *
 *   npm run templates
 */
import fs from "node:fs";
import path from "node:path";
import { buildTemplate, TEMPLATE_NAMES, type TemplateKind } from "@/lib/exports/workbook";

const outDir = path.join(process.cwd(), "exports");
fs.mkdirSync(outDir, { recursive: true });

const kinds: TemplateKind[] = ["STUDENT", "CURRICULUM", "ASSESSMENT"];

for (const kind of kinds) {
  const buffer = await buildTemplate(kind);
  const target = path.join(outDir, TEMPLATE_NAMES[kind]);
  fs.writeFileSync(target, buffer);
  console.log(`wrote ${path.relative(process.cwd(), target)} (${(buffer.length / 1024).toFixed(1)} KB)`);
}

console.log("\nEach template contains the column headers plus one clearly fictional example row.");
console.log("Delete the example row before importing real data.");
