import { sql } from "drizzle-orm";
//#region src/health.ts
/**
* A `SELECT 1` round-trip probe over any query-capable handle.
*
* Returns a `HealthCheck` whose `check()` NEVER throws — a failed query becomes
* `status:'down'` with a GENERIC `detail`. The raw driver error is deliberately
* swallowed: it can carry a DSN, credentials, or host topology and must never
* reach an admin screen or log (info-disclosure hard floor).
*/
function healthCheck(db, opts) {
	const name = opts?.name ?? "db";
	return {
		name,
		async check() {
			const start = Date.now();
			try {
				await db.execute(sql`SELECT 1`);
				return {
					name,
					status: "ok",
					latencyMs: Date.now() - start
				};
			} catch {
				return {
					name,
					status: "down",
					detail: "query failed",
					latencyMs: Date.now() - start
				};
			}
		}
	};
}
//#endregion
export { healthCheck };
