const loadEnv = require('../config/loadEnv');
const ledgerMigrationService = require('../services/ledgerMigrationService');

loadEnv();

const result = ledgerMigrationService.buildDryRun({ persist: true });

console.log('[ledger-db-dry-run] mode:', result.mode);
console.log('[ledger-db-dry-run] output:', result.dryRunPath);
console.log('[ledger-db-dry-run] documents:', result.totalDocuments);
console.log('[ledger-db-dry-run] warnings:', result.warningCount);

for (const row of result.collections) {
  console.log(`[ledger-db-dry-run] ${row.key} -> ${row.collection}: ${row.count}`);
}

if (result.warnings.length) {
  for (const warning of result.warnings) {
    console.warn('[ledger-db-dry-run] warning:', warning);
  }
}

process.exit(result.ok ? 0 : 1);
