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

export const dynamic = 'force-dynamic';

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

/**
 * Single fight-card proxy (Wave 6, S25 rule). Forwards to /api/fight/:id.
 * Unknown/unavailable card → 404 (honest, no fabricated card).
 */
export async function GET(_req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const fid = String(id || '').replace(/[^0-9]/g, '');
  if (!fid) return NextResponse.json({ error: 'not found' }, { status: 404 });
  try {
    const upstream = await fetch(`${BACKEND_URL}/api/fight/${encodeURIComponent(fid)}`, {
      method: 'GET',
      headers: { Accept: 'application/json' },
    });
    const data = await upstream.json().catch(() => ({}));
    return NextResponse.json(data, { status: upstream.status });
  } catch {
    return NextResponse.json({ error: 'card not found' }, { status: 404 });
  }
}
