"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); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DevModeController = void 0;
//#region imports
const lib_1 = require("taon/lib");
const lib_2 = require("tnp-core/lib");
const lib_3 = require("tnp-helpers/lib");
const dev_mode_models_1 = require("./dev-mode.models");
const dev_mode_repository_1 = require("./dev-mode.repository");
//#endregion
let DevModeController = class DevModeController extends lib_3.TaonBaseCliWorkerController {
    devModeRepository = this.injectKvRepository(dev_mode_repository_1.DevModeRepository);
    //#region  get all dev mode projects for given framework version
    setAsLeadProjectAndReturnDependcies(body, dirtyBuild) {
        //#region @backendFunc
        return async (req, res) => {
            body = dev_mode_models_1.DevMode.ProjectBuildNotificaiton.from(body);
            return await this.devModeRepository.setAsLeadProjectAndReturnDependcies(body, dirtyBuild);
        };
        //#endregion
    }
    //#endregion
    getWhatShouldBeRebuild(body) {
        //#region @backendFunc
        return async (req, res) => {
            body = dev_mode_models_1.DevMode.ProjectBuildNotificaiton.from(body);
            return await this.devModeRepository.getWhatShouldBeRebuild(body);
        };
        //#endregion
    }
    //#region  get all dev mode projects for given framework version
    finishLeadBuildAndUnregisterLeadProject(body) {
        //#region @backendFunc
        return async (req, res) => {
            body = dev_mode_models_1.DevMode.ProjectBuildNotificaiton.from(body);
            return await this.devModeRepository.finishLeadBuildAndUnregisterLeadProject(body);
        };
        //#endregion
    }
    //#endregion
    //#region  check if still build leader
    checkIfStillBuildLeader(body) {
        //#region @backendFunc
        return async (req, res) => {
            body = dev_mode_models_1.DevMode.ProjectBuildNotificaiton.from(body);
            return await this.devModeRepository.checkIfStillBuildLeader(body);
        };
        //#endregion
    }
    //#endregion
    //#region API
    //#region API / update dev mode pool
    updatePool(body) {
        //#region @backendFunc
        return async (req, res) => {
            body = dev_mode_models_1.DevMode.ProjectBuildNotificaiton.from(body);
            return this.devModeRepository.updatePool(body);
        };
        //#endregion
    }
    //#endregion
    //#region API / delete from dev mode pool
    deleteFromPool(body) {
        //#region @backendFunc
        return async (req, res) => {
            body = dev_mode_models_1.DevMode.ProjectBuildNotificaiton.from(body);
            return this.devModeRepository.deleteFromPool(body);
        };
        //#endregion
    }
    //#endregion
    //#region API / get all dev mode projects for given framework version
    getAllDevModeProjects(frameworkVersion) {
        //#region @backendFunc
        return async (req, res) => {
            const data = await this.devModeRepository.getPoolOfDevModePorjects(frameworkVersion);
            return data;
        };
        //#endregion
    }
    //#endregion
    //#region API / get all framework version in dev mode
    getAllFrameworkVersionInDevMode() {
        //#region @backendFunc
        return async (req, res) => {
            const data = await this.devModeRepository.getAllFrameworkVersionInDevMode();
            return data;
        };
        //#endregion
    }
    //#endregion
    //#region API / get db location
    getDbLocation() {
        //#region @backendFunc
        return async (req, res) => {
            const data = await this.devModeRepository.jsonDbLocation;
            return data;
        };
        //#endregion
    }
    //#endregion
    //#region API / get log messages
    getLogMessages(last) {
        //#region @backendFunc
        return async (req, res) => {
            const data = await this.devModeRepository
                .getAllLogMessage()
                .slice(-1 * Number(last));
            return data;
        };
        //#endregion
    }
    //#endregion
    //#region API / get log messages
    clearLogMessages() {
        //#region @backendFunc
        return async (req, res) => {
            await this.devModeRepository.clearMessage();
            return true;
        };
        //#endregion
    }
};
exports.DevModeController = DevModeController;
__decorate([
    (0, lib_1.POST)(),
    __param(0, (0, lib_1.Body)()),
    __param(1, (0, lib_1.Query)('dirtyBuild')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [dev_mode_models_1.DevMode.ProjectBuildNotificaiton, Object]),
    __metadata("design:returntype", Object)
], DevModeController.prototype, "setAsLeadProjectAndReturnDependcies", null);
__decorate([
    (0, lib_1.GET)(),
    __param(0, (0, lib_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [dev_mode_models_1.DevMode.ProjectBuildNotificaiton]),
    __metadata("design:returntype", Object)
], DevModeController.prototype, "getWhatShouldBeRebuild", null);
__decorate([
    (0, lib_1.POST)(),
    __param(0, (0, lib_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [dev_mode_models_1.DevMode.ProjectBuildNotificaiton]),
    __metadata("design:returntype", Object)
], DevModeController.prototype, "finishLeadBuildAndUnregisterLeadProject", null);
__decorate([
    (0, lib_1.GET)(),
    __param(0, (0, lib_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [dev_mode_models_1.DevMode.ProjectBuildNotificaiton]),
    __metadata("design:returntype", Object)
], DevModeController.prototype, "checkIfStillBuildLeader", null);
__decorate([
    (0, lib_1.POST)(),
    __param(0, (0, lib_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [dev_mode_models_1.DevMode.ProjectBuildNotificaiton]),
    __metadata("design:returntype", Object)
], DevModeController.prototype, "updatePool", null);
__decorate([
    (0, lib_1.POST)(),
    __param(0, (0, lib_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [dev_mode_models_1.DevMode.ProjectBuildNotificaiton]),
    __metadata("design:returntype", Object)
], DevModeController.prototype, "deleteFromPool", null);
__decorate([
    (0, lib_1.GET)(),
    __param(0, (0, lib_1.Query)('frameworkVersion')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Object)
], DevModeController.prototype, "getAllDevModeProjects", null);
__decorate([
    (0, lib_1.GET)(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Object)
], DevModeController.prototype, "getAllFrameworkVersionInDevMode", null);
__decorate([
    (0, lib_1.GET)(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Object)
], DevModeController.prototype, "getDbLocation", null);
__decorate([
    (0, lib_1.GET)(),
    __param(0, (0, lib_1.Query)('last')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number]),
    __metadata("design:returntype", Object)
], DevModeController.prototype, "getLogMessages", null);
__decorate([
    (0, lib_1.GET)(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Object)
], DevModeController.prototype, "clearLogMessages", null);
exports.DevModeController = DevModeController = __decorate([
    (0, lib_1.TaonController)({
        className: 'DevModeController',
    })
], DevModeController);
//# sourceMappingURL=dev-mode.controller.js.map