import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';
import { envs } from 'src/common/config/envs';
import * as schema from '../index';
import { seedAdminRole } from './admin-role.seed';
import { seedLocalities } from './localities';
import { seedMunicipalites } from './municipalities';
import { seedParishes } from './parishes';
import { seedStates } from './states';
import { seedUserAdmin } from './user-admin.seed';
import {seedProducts} from './inventory.seed'

async function main() {
  const pool = new Pool({
    connectionString: envs.dataBaseUrl,
    ssl: envs.node_env === 'production' ? { rejectUnauthorized: false } : false,
  });

  const db = drizzle(pool, { schema });

  try {
    // Run seeds in order
    await seedStates(db);
    await seedMunicipalites(db);
    await seedParishes(db);
    await seedLocalities(db);
    await seedAdminRole(db);
    await seedUserAdmin(db);
    await seedProducts(db);

    console.log('All seeds completed successfully');
  } catch (error) {
    console.error('Error seeding database:', error);
  } finally {
    await pool.end();
  }
}

main();
