import { NextResponse } from "next/server";
import { requireAdminApiUser } from "@/lib/auth/admin";
import { getAuditSimulationDetail } from "@/lib/audits/server";

type RouteContext = {
  params: Promise<{ id: string }>;
};

export async function GET(_request: Request, context: RouteContext) {
  const user = await requireAdminApiUser();

  if (!user) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }

  const { id } = await context.params;
  const simulation = await getAuditSimulationDetail(user.id, id);

  if (!simulation) {
    return NextResponse.json({ error: "Simulacion no encontrada." }, { status: 404 });
  }

  return NextResponse.json({ ok: true, simulation });
}
