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

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

const status = rewardReadinessService.getStatus();
const result = {
  ok: Boolean(status.latestHttpSmoke?.ok),
  mode: 'reward-rollout-status',
  readinessStatus: status.status,
  readinessScore: status.readinessScore,
  rolloutSummary: {
    connected: status.summary.rolloutConnectedServices || 0,
    ready: status.summary.rolloutReadyServices || 0,
    total: status.summary.rolloutTotalServices || 0
  },
  rolloutPlan: status.rolloutPlan,
  latestHttpSmoke: {
    ok: status.latestHttpSmoke?.ok || false,
    checkedAt: status.latestHttpSmoke?.checkedAt || null,
    passedServices: status.latestHttpSmoke?.passedServices || 0,
    totalServices: status.latestHttpSmoke?.totalServices || 0
  },
  checkedAt: new Date().toISOString()
};

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

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