/**
 * Bulk import Disney Lorcana cards from lorcana-api.com /bulk/cards.
 *
 * Usage:
 *   node --env-file=.env.local scripts/bulk-import-lorcana.js
 *
 * Options (env vars):
 *   DRY_RUN — "true" to fetch and count without writing to DB
 */

import { neon } from '@neondatabase/serverless';

import { runBulkLorcanaSync } from '../lib/card-import/lorcana-bulk.js';

if (!process.env.POSTGRES_URL) {
  console.error('POSTGRES_URL is required');
  process.exit(1);
}

const DRY_RUN = process.env.DRY_RUN === 'true';
const sql = neon(process.env.POSTGRES_URL, { fullResults: false });

async function run() {
  console.log(`[bulk-import-lorcana] Starting (dryRun=${DRY_RUN})`);

  const summary = await runBulkLorcanaSync({ sql, dryRun: DRY_RUN });

  console.log('[bulk-import-lorcana] Complete!');
  console.log(`[bulk-import-lorcana] Total in file: ${summary.totalInFile}`);
  console.log(`[bulk-import-lorcana] Upserted: ${summary.upserted}`);
  console.log(`[bulk-import-lorcana] Errors: ${summary.errors}`);
}

run().catch((err) => {
  console.error('[bulk-import-lorcana] Fatal error:', err);
  process.exit(1);
});
