import { NextResponse } from "next/server";
import { runPeriodicNormativeVerification } from "@/lib/compliance/regulations";
import { isAuthorizedCronRequest } from "@/lib/cron/auth";

export const runtime = "nodejs";

async function runVerification(request: Request) {
  if (!isAuthorizedCronRequest(request)) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }

  const payload = await runPeriodicNormativeVerification(new Date());
  return NextResponse.json({
    ok: true,
    payload,
  });
}

export async function GET(request: Request) {
  return runVerification(request);
}

export async function POST(request: Request) {
  return runVerification(request);
}
