import { NextResponse } from 'next/server';

export const dynamic = 'force-dynamic';

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

/**
 * Snapshot summary proxy (Session 57, Phase 0) — forwards
 * GET /api/snapshot/summary (real graded count + last pipeline run) for the
 * HeartbeatBar. Static segment wins over the [sport] dynamic route.
 */
export async function GET() {
  try {
    const upstream = await fetch(`${BACKEND_URL}/api/snapshot/summary`, {
      method: 'GET',
      headers: { Accept: 'application/json' },
    });
    const data = await upstream.json().catch(() => ({ graded: 0, updated_at: null, sports: {} }));
    return NextResponse.json(data, { status: upstream.ok ? 200 : upstream.status });
  } catch {
    return NextResponse.json({ graded: 0, updated_at: null, sports: {} }, { status: 200 });
  }
}
