import { NextResponse } from 'next/server';

export const dynamic = 'force-dynamic';

const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000';

/**
 * Accuracy proxy (Session 55) — forwards GET /api/accuracy to Express (the
 * self-learning loop's rolling track record). Thin pass-through; the dashboard
 * header + grade card read this. Empty-safe on any upstream failure.
 */
export async function GET() {
  try {
    const upstream = await fetch(`${BACKEND_URL}/api/accuracy`, {
      method: 'GET',
      headers: { Accept: 'application/json' },
      cache: 'no-store',
    });
    const data = await upstream.json().catch(() => ({ overall: null, sports: {} }));
    return NextResponse.json(data, { status: upstream.ok ? 200 : upstream.status });
  } catch {
    return NextResponse.json({ overall: null, sports: {}, min_sample: 8, updated_at: null }, { status: 200 });
  }
}
