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

const guardService = require('../services/ledgerMongoPostSwitchGuardService');

function hasFlag(name) {
  return process.argv.includes(`--${name}`);
}

async function main() {
  const result = await guardService.runGuard({
    reason: 'cli-post-switch-guard',
    rollbackOnFailure: hasFlag('rollback-on-failure'),
    confirmRollback: hasFlag('confirm-rollback'),
    actor: 'cli-post-switch-guard'
  });
  console.log(JSON.stringify(result, null, 2));
  if (!result.ok) process.exitCode = 1;
}

main().catch((err) => {
  console.error(JSON.stringify({ ok: false, error: err.message }, null, 2));
  process.exitCode = 1;
});
