import { NextResponse } from "next/server";
import { requireAdminApiUser } from "@/lib/auth/admin";
import { verifyOfficialNormativeSources } from "@/lib/compliance/regulations";

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

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

  const body = (await request.json().catch(() => ({}))) as { sourceIds?: unknown };
  const sourceIds = Array.isArray(body.sourceIds)
    ? body.sourceIds.filter((item): item is string => typeof item === "string" && item.trim().length > 0).map((item) => item.trim())
    : undefined;

  const results = await verifyOfficialNormativeSources(sourceIds);
  return NextResponse.json({ ok: true, results });
}
