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

const rewardReadinessService = require('../services/rewardReadinessService');

const status = rewardReadinessService.getStatus();
const result = {
  ok: Boolean(status.liveCanaryPreflight?.ok),
  mode: 'reward-live-canary-preflight',
  readinessStatus: status.status,
  readinessScore: status.readinessScore,
  confirmRequiredForLive: status.liveCanaryPreflight?.confirmRequiredForLive || 'LIVE_SIMULATION_WRITE',
  preflight: status.liveCanaryPreflight,
  latestLiveCanary: {
    ok: status.latestLiveCanary?.ok || false,
    live: status.latestLiveCanary?.live || false,
    mode: status.latestLiveCanary?.mode || '',
    serviceName: status.latestLiveCanary?.serviceName || '',
    checkedAt: status.latestLiveCanary?.checkedAt || null
  },
  latestHttpSmoke: {
    ok: status.latestHttpSmoke?.ok || false,
    passedServices: status.latestHttpSmoke?.passedServices || 0,
    totalServices: status.latestHttpSmoke?.totalServices || 0,
    checkedAt: status.latestHttpSmoke?.checkedAt || null
  },
  checkedAt: new Date().toISOString()
};

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

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