import { NextResponse } from "next/server";

export function isCronRequestAuthorized(request: Request) {
  const jobSecret = (process.env.VIBEWORK_JOB_SECRET || "").trim();
  const authHeader = request.headers.get("authorization");
  return Boolean(jobSecret) && authHeader === `Bearer ${jobSecret}`;
}

export function cronUnauthorizedResponse(surface: string) {
  console.warn(`[${surface}] Unauthorized cron request`);
  return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
