import { spawnSync } from 'node:child_process';

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

function main() {
  const steps: Array<{ label: string; args: string[] }> = [
    {
      label: 'uat users seed',
      args: [...NODE_TS_RUNTIME_ARGS, 'src/db/seeds/uat-users.seed.ts']
    },
    {
      label: 'crm uat data seed',
      args: [...NODE_TS_RUNTIME_ARGS, 'src/db/seeds/crm-uat.seed.ts']
    }
  ];

  for (const step of steps) {
    const result = spawnSync(process.execPath, step.args, {
      stdio: 'inherit',
      env: process.env
    });

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

main();
