import { NextResponse } from "next/server";
import { apiAuth } from "@/lib/auth/guards";
import { osrmHealthy } from "@/lib/geo/osrm";
import { nominatimHealthy } from "@/lib/geo/nominatim";

// Geo-Dienst-Health (OSRM/Nominatim). NICHT der öffentliche Container-
// Healthcheck (das ist /api/health) — dieser Endpunkt ist auth-gated (401).
export const dynamic = "force-dynamic";

export async function GET() {
  const authResult = await apiAuth();
  if (!authResult.ok) return authResult.response;

  const [osrm, nominatim] = await Promise.all([osrmHealthy(), nominatimHealthy()]);
  const status = osrm && nominatim ? "ok" : "degraded";
  return NextResponse.json({
    status,
    osrm: osrm ? "up" : "down",
    nominatim: nominatim ? "up" : "down",
  });
}
