import { NextRequest, NextResponse } from 'next/server';
import { cachedBackendJson } from '@/services/odds-cache';

export const dynamic = 'force-dynamic';
export const revalidate = 300;

export async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  if (!id) return NextResponse.json({ error: 'Missing game id.' }, { status: 400 });

  try {
    const game = await cachedBackendJson<Record<string, unknown>>(
      `game:detail:${id}`,
      'mixed',
      'game_detail',
      `/api/games/${encodeURIComponent(id)}`,
      300,
    );
    return NextResponse.json(game);
  } catch {
    return NextResponse.json({ error: 'Game not found.' }, { status: 404 });
  }
}
