"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 DevBuildRepository_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DevBuildRepository = void 0;
//#region imports
const lib_1 = require("taon/lib");
const project_1 = require("../../project");
const dev_mode_models_1 = require("../dev-mode/dev-mode.models");
//#endregion
let DevBuildRepository = class DevBuildRepository extends lib_1.TaonBaseKvRepository {
    static { DevBuildRepository_1 = this; }
    //#region fields & getters
    static projectsInBuild = [];
    project = void 0;
    envOptions = void 0;
    setProject({ project, port, buildType, }) {
        DevBuildRepository_1.projectsInBuild.push({ project, port, buildType });
        this.project = project;
    }
    setEnvOptions(envOptions) {
        this.envOptions = envOptions;
    }
    getProject() {
        return this.project;
    }
    async getProjectInfo() {
        //#region @backendFunc
        const dataToRequest = this.dataToRequest({
            buildStatusInfo: this.project.taonBuildObserver.buildStatusInfo,
        });
        return dataToRequest;
        //#endregion
    }
    //#region private methods / get main worker contorller
    async getMainWorkerController() {
        //#region @backendFunc
        const devModeController = await project_1.Project.ins.taonProjectsWorker.devModeWorker.getRemoteControllerFor({
            methodOptions: {
                calledFrom: 'dev build repository',
            },
        });
        return devModeController;
        //#endregion
    }
    //#endregion
    //#region public methods / update pool
    async updatePool(opt) {
        //#region @backendFunc
        const devModeControllerMainWorker = await this.getMainWorkerController();
        const dataToRequest = this.dataToRequest(opt);
        const data = await devModeControllerMainWorker.updatePool(dataToRequest).request();
        return data.body.json;
        //#endregion
    }
    //#endregion
    //#region public methods / delete from pool
    async deleteFromPool(data) {
        //#region @backendFunc
        const devModeControllerMainWorker = await this.getMainWorkerController();
        const deleteFromPoolData = await devModeControllerMainWorker.deleteFromPool(data).request();
        return deleteFromPoolData.body.json;
        //#endregion
    }
    //#endregion
    //#region public method / get all projects in process
    allProjectsInProcess() {
        return DevBuildRepository_1.projectsInBuild.map(child => {
            return dev_mode_models_1.DevMode.ProjectBuildNotificaiton.from({
                name: child.project.name,
                nameForNpmPackage: child.project.nameForNpmPackage,
                location: child.project.location,
                port: child.port,
                buildType: child.buildType,
                devModeDependenciesNames: this.project.taonJson.devModeDependenciesForNpmLib,
                coreContainerVersion: child.project.framework.frameworkVersion,
            });
        });
    }
    //#endregion
    //#region private method / data to request
    dataToRequest(opt) {
        //#region @backendFunc
        opt = opt || {};
        this.project.taonJson.reloadFromDisk();
        const dataToRequest = dev_mode_models_1.DevMode.ProjectBuildNotificaiton.from({
            name: this.project.name,
            buildType: this.envOptions?.build?.watch ? 'watch' : 'normal',
            nameForNpmPackage: this.project.nameForNpmPackage,
            location: this.project.location,
            port: this.project.ins.currentActionPort,
            devModeDependenciesNames: this.project.taonJson.devModeDependenciesForNpmLib,
            buildStatusInfo: opt.buildStatusInfo,
            coreContainerVersion: this.project.taonJson.frameworkVersion,
        });
        return dataToRequest;
        //#endregion
    }
};
exports.DevBuildRepository = DevBuildRepository;
exports.DevBuildRepository = DevBuildRepository = DevBuildRepository_1 = __decorate([
    (0, lib_1.TaonRepository)({
        className: 'DevBuildRepository',
    })
], DevBuildRepository);
//# sourceMappingURL=dev-build.repository.js.map