import 'reflect-metadata';
import { config } from 'dotenv';
import { resolve } from 'path';

config({ path: resolve(__dirname, '../../.env') });

import { NestFactory } from '@nestjs/core';
import { AppModule } from '../app.module';
import { DemoFreightDataSeeder } from '../seed/demo-freight-data.seeder';

async function main() {
  const app = await NestFactory.createApplicationContext(AppModule, {
    logger: ['error', 'warn', 'log'],
  });

  try {
    const seeder = app.get(DemoFreightDataSeeder);
    await seeder.run();
    console.log('Freight demo data seeded (wagons, approval rules, staff users).');
  } finally {
    await app.close();
  }
}

main().catch((err) => {
  console.error('Freight demo seed failed:', err);
  process.exit(1);
});
