import { NextResponse } from "next/server";
import { adminConfigurationStatus, appVersion, checkStorage } from "@/lib/runtime/config";
import { getSmtpSettings, isSmtpConfigured } from "@/lib/mail/config";

export async function GET() {
  let storage = "ok";

  try {
    await checkStorage();
  } catch {
    storage = "error";
  }

  const smtpSettings = await getSmtpSettings();

  return NextResponse.json({
    status: storage === "ok" ? "ok" : "error",
    version: appVersion,
    storage,
    admin: adminConfigurationStatus(),
    smtp: isSmtpConfigured(smtpSettings) ? "configured" : "missing",
    timestamp: new Date().toISOString(),
  });
}
