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

const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8001';

export async function GET(
  request: NextRequest,
  { params }: { params: Promise<{ jobId: string }> }
) {
  try {
    const { jobId } = await params;
    const { searchParams } = new URL(request.url);
    const limit = searchParams.get('limit') || '1000';

    const response = await fetch(`${API_BASE_URL}/jobs/${jobId}/reviews?limit=${limit}`);

    if (!response.ok) {
      return NextResponse.json(
        { error: 'Failed to get reviews' },
        { status: response.status }
      );
    }

    const data = await response.json();
    // API returns { job_id, reviews: [...], count }, we just need the reviews array
    return NextResponse.json({ reviews: data.reviews || [] });
  } catch (error) {
    console.error('Reviews API error:', error);
    return NextResponse.json(
      { error: 'Failed to get reviews' },
      { status: 500 }
    );
  }
}
