#!/usr/bin/env node
// CLI wrapper: `node scripts/seed.js [run|rollback]`

const path = require('path');
const Database = require('better-sqlite3');
const { seedDemoData } = require('../src/database/seeds/demo');
const { seedGradingScales } = require('../src/database/seeds/grading_scales');

const cmd = process.argv[2] || 'run';

(async () => {
  if (cmd !== 'run') {
    console.error(`Unknown command: ${cmd}. Use: run`);
    process.exit(1);
  }

  const DB_PATH = process.env.DB_PATH || path.join(__dirname, '..', 'data', 'school.db');
  const db = new Database(DB_PATH);
  db.pragma('foreign_keys = ON');

  try {
    await seedDemoData(db);
    await seedGradingScales(db);
    console.log('[seed] done');
  } finally {
    db.close();
  }
})();
