import { d as defineEventHandler, b2 as setResponseStatus, b as getDatabaseManager, bo as getStorageProvider, c5 as getJobQueue } from '../../nitro/nitro.mjs';
import 'node:crypto';
import 'jsonwebtoken';
import 'node:fs';
import 'node:module';
import 'node:path';
import 'node:url';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'pino';
import 'drizzle-orm/better-sqlite3';
import 'drizzle-orm/node-postgres';
import 'drizzle-orm/mysql2';
import 'better-sqlite3';
import 'pg';
import 'mysql2/promise';
import 'drizzle-orm';
import 'fs';
import 'path';
import 'prom-client';
import 'bcryptjs';
import '@node-rs/argon2';
import 'node:async_hooks';
import 'crypto';
import 'node:dns';
import 'node:util';
import 'node:net';
import 'fs/promises';
import 'url';
import 'semver';

async function timeCheck(required, fn) {
  const start = process.hrtime.bigint();
  try {
    const result = await fn();
    return {
      status: result.status,
      required,
      durationMs: Math.round(Number(process.hrtime.bigint() - start) / 1e6),
      detail: result.detail
    };
  } catch (error) {
    return {
      status: "fail",
      required,
      durationMs: Math.round(Number(process.hrtime.bigint() - start) / 1e6),
      detail: error instanceof Error ? error.message : String(error)
    };
  }
}
const readyz_get = defineEventHandler(async (event) => {
  const checks = {};
  checks.database = await timeCheck(true, async () => {
    var _a, _b;
    const status = await getDatabaseManager().getStatus();
    if (!status.connected) {
      return { status: "fail", detail: (_a = status.error) != null ? _a : "not connected" };
    }
    return {
      status: "ok",
      detail: `${status.dialect} (${(_b = status.tablesCount) != null ? _b : 0} tables)`
    };
  });
  checks.storage = await timeCheck(false, () => {
    try {
      const provider = getStorageProvider();
      return Promise.resolve({ status: "ok", detail: provider.getType() });
    } catch (error) {
      return Promise.resolve({
        status: "fail",
        detail: error instanceof Error ? error.message : String(error)
      });
    }
  });
  checks.jobQueue = await timeCheck(false, () => {
    try {
      getJobQueue();
      return Promise.resolve({ status: "ok", detail: "running" });
    } catch (error) {
      return Promise.resolve({
        status: "fail",
        detail: error instanceof Error ? error.message : String(error)
      });
    }
  });
  const requiredFailed = Object.values(checks).some((c) => c.required && c.status !== "ok");
  const overall = requiredFailed ? "not_ready" : "ready";
  if (requiredFailed) {
    setResponseStatus(event, 503);
  }
  return {
    status: overall,
    timestamp: (/* @__PURE__ */ new Date()).toISOString(),
    uptime: process.uptime(),
    checks
  };
});

export { readyz_get as default };
//# sourceMappingURL=readyz.get.mjs.map
