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

export async function GET(
  request: NextRequest,
  { params }: { params: { leagueId: string } }
) {
  const { leagueId } = params;
  
  const apiBaseUrl = process.env.API_BASE_URL || 'http://localhost:3000';
  
  try {
    const response = await fetch(`${apiBaseUrl}/media/leagues/${leagueId}/logo`, {
      method: 'GET',
    });

    if (!response.ok) {
      return new NextResponse(null, { status: 404 });
    }

    const buffer = await response.arrayBuffer();
    
    return new NextResponse(buffer, {
      headers: {
        'Content-Type': 'image/png',
        'Cache-Control': 'public, max-age=3600',
      },
    });
  } catch (error) {
    console.error('Error fetching league logo:', error);
    return new NextResponse(null, { status: 500 });
  }
}