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

export const dynamic = 'force-dynamic';

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

/** Lineup-confirmation proxy (Session 64 / A1-S5). */
export async function GET(req: NextRequest, { params }: { params: Promise<{ sport: string }> }) {
  const { sport } = await params;
  try {
    const upstream = await fetch(`${BACKEND_URL}/api/schedule/${encodeURIComponent(String(sport).toLowerCase())}/lineups${req.nextUrl.search}`, {
      headers: { Accept: 'application/json' },
    });
    const data = await upstream.json().catch(() => ({ byPlayer: {}, postedTeams: [] }));
    return NextResponse.json(data, { status: upstream.ok ? 200 : upstream.status });
  } catch {
    return NextResponse.json({ byPlayer: {}, postedTeams: [] }, { status: 200 });
  }
}
