import { NextResponse } from "next/server";
import { requireSuperadmin } from "@/lib/admin-auth";
import { computeAllBenchmarks } from "@/lib/services/benchmark-engine";

export const dynamic = "force-dynamic";
export const maxDuration = 300;

export async function POST() {
  const denied = await requireSuperadmin();
  if (denied) return denied;

  try {
    const result = await computeAllBenchmarks();
    return NextResponse.json({ success: true, ...result });
  } catch (err) {
    return NextResponse.json(
      { error: err instanceof Error ? err.message : "Compute failed" },
      { status: 500 },
    );
  }
}
