import { NextResponse } from 'next/server';
import { getSetupRunReport } from '@/features/setup/server/setup-state.service';
import { AuthError, requireSystemRole } from '@/lib/auth/session';

export async function GET() {
  try {
    await requireSystemRole('super_admin');
    return NextResponse.json(await getSetupRunReport());
  } catch (error) {
    if (error instanceof AuthError) {
      return NextResponse.json({ message: error.message }, { status: error.status });
    }

    return NextResponse.json({ message: 'Unable to load setup report' }, { status: 500 });
  }
}
