"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.healthHandler = healthHandler;
exports.readyHandler = readyHandler;
/** Create health endpoint handler (unauthenticated). */
function healthHandler(cache, cacheTtl, encryptedStore) {
    return (_req, res) => {
        if (encryptedStore) {
            // JIT mode: freshness is proved by KMS on each request, no TTL to expire
            res.json({
                status: "ok",
                mode: "jit",
                revision: encryptedStore.getRevision(),
                lastRefreshAt: encryptedStore.getStoredAt(),
                expired: false,
            });
        }
        else {
            const expired = cacheTtl !== undefined && cache.isExpired(cacheTtl);
            res.json({
                status: "ok",
                mode: "cached",
                revision: cache.getRevision(),
                lastRefreshAt: cache.getLastRefreshAt(),
                expired,
            });
        }
    };
}
/** Create readiness endpoint handler (unauthenticated). */
function readyHandler(cache, cacheTtl, encryptedStore) {
    return (_req, res) => {
        if (encryptedStore) {
            // JIT mode: ready when encrypted artifact is loaded
            if (!encryptedStore.isReady()) {
                res.status(503).json({ ready: false, reason: "not_loaded" });
                return;
            }
            res.status(200).json({ ready: true });
        }
        else {
            if (!cache.isReady()) {
                res.status(503).json({ ready: false, reason: "not_loaded" });
                return;
            }
            if (cacheTtl !== undefined && cache.isExpired(cacheTtl)) {
                res.status(503).json({ ready: false, reason: "cache_expired" });
                return;
            }
            res.status(200).json({ ready: true });
        }
    };
}
//# sourceMappingURL=health.js.map