/**
 * Synthetic seed (the "every pipeline stage" fixture).
 *
 * Bootstraps the same ports/roles/profile as `seed.ts` then loads
 * `seedSyntheticPortData()` per port - 12 clients, one per pipeline
 * stage plus archive variants, designed for thoroughly testing the
 * CRM end-to-end.
 *
 * Use the realistic seed (`pnpm db:seed`) for shapes that mirror the
 * production NocoDB clone.
 *
 * Run with: pnpm db:seed:synthetic
 */

import 'dotenv/config';
import { seedBootstrap } from './seed-bootstrap';
import { seedSyntheticPortData, type SyntheticSeedSummary } from './seed-synthetic-data';

async function seed() {
  console.log('Seeding Port Nimara CRM (synthetic test fixture)...');

  const portIds = await seedBootstrap();

  console.log('');
  console.log('Seeding per-port synthetic fixtures...');

  const summaries: Array<{ name: string; summary: SyntheticSeedSummary | null }> = [];
  for (const p of portIds) {
    console.log(`  [${p.slug}] seeding synthetic data...`);
    const summary = await seedSyntheticPortData(p.id, p.slug);
    summaries.push({ name: p.name, summary });
  }

  console.log('');
  console.log('─── Summary ───────────────────────────────────────────────');
  for (const s of summaries) {
    if (s.summary === null) {
      console.log(`  ✓ Port "${s.name}" - already seeded (skipped)`);
    } else {
      const x = s.summary;
      console.log(
        `  ✓ Port "${s.name}" - ${x.berths} berths, ${x.clients} clients, ${x.companies} companies, ${x.yachts} yachts, ${x.interests} interests, ${x.residentialClients} residential clients`,
      );
    }
  }
  console.log('');
  console.log('Synthetic seed complete!');

  process.exit(0);
}

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