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

loadEnv();

const result = ledgerConsistencyService.getStatus();

console.log('[ledger-shadow-compare] ok:', result.ok);
console.log('[ledger-shadow-compare] checkedAt:', result.checkedAt);
console.log('[ledger-shadow-compare] source rows:', result.totalSourceRows);
console.log('[ledger-shadow-compare] shadow rows:', result.totalShadowRows);
console.log('[ledger-shadow-compare] issues:', result.issueCount);

result.collections.forEach((row) => {
  const status = row.ok ? 'OK' : `ISSUE ${row.issue}`;
  console.log(`[ledger-shadow-compare] ${row.collection}: ${row.sourceCount}/${row.shadowCount} ${status}`);
});

if (!result.ok) process.exit(1);
