var DevBuildRepository_1;
//#region imports
import { TaonBaseKvRepository, TaonRepository, } from 'taon/lib';
import { Project } from '../../project';
import { DevMode } from '../dev-mode/dev-mode.models';
//#endregion
let DevBuildRepository = class DevBuildRepository extends 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.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 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 = 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
    }
};
DevBuildRepository = DevBuildRepository_1 = __decorate([
    TaonRepository({
        className: 'DevBuildRepository',
    })
], DevBuildRepository);
export { DevBuildRepository };
//# sourceMappingURL=dev-build.repository.js.map