"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const decorators_1 = require("../decorators");
const Server_1 = require("../Server");
let HealthService = class HealthService {
    constructor() {
        this.started = false;
    }
    start(server) {
        return __awaiter(this, void 0, void 0, function* () {
            this.healthClient = server.healthClient;
            this.version = server.version;
        });
    }
    live() {
        this.started = true;
    }
    getHealth(res, thisInstance) {
        return __awaiter(this, void 0, void 0, function* () {
            if (this.started) {
                if (thisInstance === 'true' || (yield this.healthClient.hasServerStarted())) {
                    res.status(200).json({
                        version: this.version
                    });
                    return;
                }
            }
            res.status(503).send("Server has not fully started yet");
        });
    }
};
__decorate([
    decorators_1.Start(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Server_1.Server]),
    __metadata("design:returntype", Promise)
], HealthService.prototype, "start", null);
__decorate([
    decorators_1.ServerStarted(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], HealthService.prototype, "live", null);
__decorate([
    decorators_1.Get("/"),
    __param(0, decorators_1.Response()),
    __param(1, decorators_1.Query('thisInstance')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String]),
    __metadata("design:returntype", Promise)
], HealthService.prototype, "getHealth", null);
HealthService = __decorate([
    decorators_1.BaseRoute("/health"),
    decorators_1.ServiceName('health'),
    decorators_1.Cors("/")
], HealthService);
exports.HealthService = HealthService;
//# sourceMappingURL=HealthService.js.map