/**
 * GET /api/analyzer/aggregate-reports/:id
 *
 * Returns the full report row. Frontend polls this for completion when the
 * report is in 'pending'/'running' status.
 */

import { NextRequest, NextResponse } from 'next/server';
import { requireAuth } from '@/lib/auth-utils';
import { getAggregateReport } from '@/lib/services/analyzer/aggregate-persistence';

export async function GET(
  _request: NextRequest,
  { params }: { params: Promise<{ id: string }> }
) {
  const { error } = await requireAuth();
  if (error) return error;
  const { id } = await params;
  const report = await getAggregateReport(id);
  if (!report) {
    return NextResponse.json({ error: 'Report not found' }, { status: 404 });
  }
  return NextResponse.json({ report });
}
