'use strict';

/**
 * GET /api/accuracy (Session 55) — the system's track record.
 *
 * Public, cache-only read of the rolling accuracy record written by
 * outcomeService (settled snapshot grades vs real results). Powers the
 * dashboard "A-rated: 68% hit rate" pill and the grade-card accuracy line.
 * NEVER triggers settlement (that's the internal cron) → no API credits spent.
 */

const express = require('express');
const { createRateLimit } = require('../middleware/rateLimit');
const outcomeService = require('../services/outcomeService');

const router = express.Router();
router.use(createRateLimit({ windowMs: 60_000, max: 60 }));

router.get('/', async (req, res) => {
  try {
    const acc = await outcomeService.getAccuracy();
    res.set('Cache-Control', 'public, max-age=300');
    return res.json(acc);
  } catch (err) {
    console.error('[accuracy]', err.message);
    return res.status(200).json({ overall: null, sports: {}, min_sample: outcomeService.MIN_SAMPLE, updated_at: null });
  }
});

module.exports = router;
