import { NextRequest, NextResponse } from "next/server";
import { runWeatherCheckSweep } from "@/lib/weatherCheck";

// Alle 2 Stunden per Systemcrontab (analog zu preshoot-reminder) — reicht für
// ein 48h-Vorlauffenster locker aus, ohne dass sich eine sich verschlechternde
// Vorhersage zu spät bemerkbar macht.
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 runWeatherCheckSweep();
  return NextResponse.json({ ok: true, ...result });
}
