import { spawnSync } from 'node:child_process';

const NODE_TS_RUNTIME_ARGS = [
  '--disable-warning=ExperimentalWarning',
  '--disable-warning=MODULE_TYPELESS_PACKAGE_JSON',
  '--experimental-strip-types'
];

function run(label: string, args: string[]) {
  const result = spawnSync(process.execPath, args, {
    stdio: 'inherit',
    env: process.env
  });

  if (result.status !== 0) {
    throw new Error(`[seed:system] ${label} failed with exit code ${result.status ?? 1}`);
  }
}

function main() {
  run('super admin seed', ['scripts/seed-super-admin.js']);
  run('system organization seed', [
    ...NODE_TS_RUNTIME_ARGS,
    'src/db/seeds/system-organization.seed.ts'
  ]);
  run('foundation seed', [...NODE_TS_RUNTIME_ARGS, 'src/db/seeds/foundation.seed.ts']);
  run('pdf template seed', [...NODE_TS_RUNTIME_ARGS, 'scripts/reseed-pdf-template-version.ts']);
}

main();
