//#region src/health.ts
/**
* Run all checks (settled — a thrown/rejected check becomes `status:'down'`, never propagates),
* roll up to the worst status: any 'down' => 'down'; else any 'degraded' => 'degraded'; else 'ok'.
* An empty check set rolls up to 'ok' (nothing unhealthy).
*/
async function aggregateHealth(checks) {
	const results = (await Promise.allSettled(checks.map(async (c) => c.check()))).map((s, i) => {
		if (s.status === "fulfilled") return s.value;
		return {
			name: checks[i].name,
			status: "down",
			detail: "check failed"
		};
	});
	return {
		status: rollup(results),
		checks: results
	};
}
function rollup(results) {
	if (results.some((r) => r.status === "down")) return "down";
	if (results.some((r) => r.status === "degraded")) return "degraded";
	return "ok";
}
//#endregion
export { aggregateHealth };
