import { NextRequest, NextResponse } from "next/server";
import { runPreshootReminderSweep } from "@/lib/preshootReminder";

// Alle 2 Stunden per Systemcrontab (analog zu google-sync) — reicht für ein
// 48h-Erinnerungsfenster locker aus, ohne dass Termine durchrutschen.
export async function GET(req: NextRequest) {
  const secret = req.nextUrl.searchParams.get("secret");
  if (!process.env.CRON_SECRET || secret !== process.env.CRON_SECRET) {
    return new NextResponse("Unauthorized", { status: 401 });
  }

  const result = await runPreshootReminderSweep();
  return NextResponse.json({ ok: true, ...result });
}
