require('../config/loadEnv')();

const readiness = require('../services/ledgerDbReadinessService');

const status = readiness.getStatus();
const result = {
  ok: Boolean(status.readSwitchPreflightOk),
  mode: 'ledger-read-switch-preflight',
  targetBackend: status.targetBackend,
  canAttachWriter: status.canAttachWriter,
  readSwitchPreflightOk: status.readSwitchPreflightOk,
  readSwitchApproved: status.readSwitchApproved,
  canSwitchReads: status.canSwitchReads,
  switchRequested: status.switchRequested,
  switchLockReason: status.switchLockReason,
  observation: status.mongoObservation,
  checks: status.checks,
  checkedAt: new Date().toISOString()
};

console.log(JSON.stringify(result, null, 2));

if (!result.ok) process.exitCode = 1;
