import { NextRequest, NextResponse } from 'next/server';

export const dynamic = 'force-dynamic';

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

/** Snapshot proxy (Session 45) — forwards GET /api/snapshot/:sport (pre-graded slate). */
export async function GET(_req: NextRequest, ctx: { params: Promise<{ sport: string }> }) {
  const { sport } = await ctx.params;
  try {
    const upstream = await fetch(`${BACKEND_URL}/api/snapshot/${encodeURIComponent(sport)}`, {
      method: 'GET',
      headers: { Accept: 'application/json' },
    });
    const data = await upstream.json().catch(() => ({ grades: [], deltas: [] }));
    return NextResponse.json(data, { status: upstream.ok ? 200 : upstream.status });
  } catch {
    return NextResponse.json({ sport, grades: [], deltas: [] }, { status: 200 });
  }
}
