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

export async function POST() {
  const user = await requireAdminApiUser();

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

  const snapshot = await refreshInstitutionalDossierSnapshot(user.id);

  return NextResponse.json({
    ok: true,
    snapshotId: snapshot.id,
    generatedAt: snapshot.generatedAt,
    dossier: snapshot.payload,
    freshness: snapshot.freshness,
  });
}
