// Writes an outcome export CSV to a file (same code as the "Export report" menu on the Trainees page).
// Usage: npx tsx scripts/export-outcomes.ts <projectId> <reportType> <outFile> [trainingProviderId]
// reportType: completion | certification | dropout | employment_placement | locality_compliant | job_retention_3m
import fs from "node:fs";
import { isOutcomeExportType, outcomeExportCsv } from "../src/services/outcomeExport.js";
import { prisma } from "../src/prisma.js";

const [projectId, type, out, providerId] = process.argv.slice(2);
if (!projectId || !type || !out || !isOutcomeExportType(type)) {
  throw new Error("Usage: npx tsx scripts/export-outcomes.ts <projectId> <reportType> <outFile> [trainingProviderId]");
}
const { csv, count } = await outcomeExportCsv(BigInt(projectId), type, providerId ? BigInt(providerId) : null);
fs.writeFileSync(out, csv, "utf8");
console.log(`${count} rows written to ${out}`);
await prisma.$disconnect();
