import { NextResponse } from "next/server";
import { db } from "@/server/db";
import { logger } from "@/server/logger";

// Liveness/readiness probe for the dashboard itself (load balancers, uptime
// checks). Public on purpose (src/proxy.ts lets it through) and deliberately
// says nothing beyond "up" or "down".
export const dynamic = "force-dynamic";

export async function GET() {
  try {
    await db.$queryRaw`SELECT 1`;
    return NextResponse.json({ status: "ok" }, { headers: { "Cache-Control": "no-store" } });
  } catch (error) {
    logger.error("health.self_check.failed", { error });
    return NextResponse.json({ status: "unavailable" }, { status: 503, headers: { "Cache-Control": "no-store" } });
  }
}
