"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__tsfTypeAliases = exports.HealthcheckService = void 0;
const tslib_1 = require("tslib");
const _a = tslib_1.__importStar(require("@zyno-io/ts-server-foundation/type-metadata-runtime"));
const __tsf_metadata_type = _a.createCompactMetadataRegistryV1("[1,[{\"kind\":6},{\"kind\":2,\"typeName\":\"() =\\u003e Promise\\u003cvoid\\u003e | void\",\"typeName\":\"HealthcheckFn\"},{\"kind\":3},{\"kind\":22,\"type\":{\"kind\":3}},{\"kind\":22,\"type\":{\"kind\":14,\"type\":{\"kind\":18,\"typeName\":\"HealthcheckResult\",\"types\":[{\"kind\":20,\"name\":\"name\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"status\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"ok\"},{\"kind\":10,\"literal\":\"error\"}]},\"optional\":false},{\"kind\":20,\"name\":\"error\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true}]}}}]]", []);
let _HealthcheckServiceMetadata_1;
class HealthcheckService {
    checks = [];
    register(name, fn) {
        this.checks.push({ name, fn });
    }
    async check() {
        for (const check of this.checks)
            await check.fn();
    }
    async checkIndividual() {
        const results = [];
        for (const check of this.checks) {
            try {
                await check.fn();
                results.push({ name: check.name, status: 'ok' });
            }
            catch (error) {
                results.push({
                    name: check.name,
                    status: 'error',
                    error: error instanceof Error ? error.message : String(error)
                });
            }
        }
        return results;
    }
    static __tsfType = _HealthcheckServiceMetadata_1 = _a.decodeCompactMetadataV1("[1,{\"kind\":16,\"name\":\"HealthcheckService\",\"typeName\":\"HealthcheckService\",\"classType\":{\"$tsf\":0},\"properties\":[],\"methods\":[{\"name\":\"register\",\"parameters\":[{\"name\":\"name\",\"type\":{\"$tsfType\":0},\"optional\":false,\"default\":false},{\"name\":\"fn\",\"type\":{\"$tsfType\":1},\"optional\":false,\"default\":false}],\"returnType\":{\"$tsfType\":2}},{\"name\":\"check\",\"parameters\":[],\"returnType\":{\"$tsfType\":3}},{\"name\":\"checkIndividual\",\"parameters\":[],\"returnType\":{\"$tsfType\":4}}],\"hasConstructor\":false,\"constructorParameters\":[]}]", [() => HealthcheckService], __tsf_metadata_type);
}
exports.HealthcheckService = HealthcheckService;
_HealthcheckServiceMetadata_1.classType = HealthcheckService;
HealthcheckService.__tsfType = _HealthcheckServiceMetadata_1;
exports.__tsfTypeAliases = JSON.parse("[1,{\"HealthcheckFn\":{\"kind\":2,\"typeName\":\"() =\\u003e Promise\\u003cvoid\\u003e | void\",\"typeName\":\"HealthcheckFn\"},\"HealthcheckResult\":{\"kind\":18,\"typeName\":\"HealthcheckResult\",\"types\":[{\"kind\":20,\"name\":\"name\",\"type\":{\"kind\":6},\"optional\":false},{\"kind\":20,\"name\":\"status\",\"type\":{\"kind\":12,\"types\":[{\"kind\":10,\"literal\":\"ok\"},{\"kind\":10,\"literal\":\"error\"}]},\"optional\":false},{\"kind\":20,\"name\":\"error\",\"type\":{\"kind\":12,\"types\":[{\"kind\":6},{\"kind\":4}]},\"optional\":true}]}}]")[1];
//# sourceMappingURL=healthcheck.service.js.map