import { TaonBaseClass } from 'taon/lib';
import { _ } from 'tnp-core/lib';
import { watcherPrefix } from '../../../../constants';
export var DevMode;
(function (DevMode) {
    DevMode.MAX_NUMBER_OF_CONCURENT_BUILDS = 1;
    let ProjectBuildStatus;
    (function (ProjectBuildStatus) {
        /**
         * External command to cancel build (TODO implement killing of processes)
         */
        ProjectBuildStatus["__CANCEL_BUILD__"] = "__CANCEL_BUILD__";
        /**
         * External command to start building (or repeat build if build active)
         */
        ProjectBuildStatus["__START_BUILD__"] = "__START_BUILD__";
        /**
         * 1. default state of porject
         */
        ProjectBuildStatus["NOT_STARTED"] = "NOT_STARTED";
        /**
         * Each project is immediatlly building because of BehaviorSubject()
         */
        ProjectBuildStatus["BUILDING"] = "BUILDING";
        /**
         * Cancelled build of project (but still building - I am not killing processes)
         */
        ProjectBuildStatus["BUILDING_BUT_CANCELLED"] = "BUILDING_BUT_CANCELLED";
        /**
         * Auto rebuild of project at the end of building
         */
        ProjectBuildStatus["BUILDING_WITH_REBUILD_AT_THE_END"] = "BUILDING_WITH_REBUILD_AT_THE_END";
        /**
         * Done building
         */
        ProjectBuildStatus["DONE_BUILDING_SUCCESS"] = "DONE_BUILDING_SUCCESS";
        /**
         * Cancelled build of project (process idle)
         */
        ProjectBuildStatus["BUILD_CANCEL_DONE"] = "BUILD_CANCEL_DONE";
        /**
         * Build error.
         */
        ProjectBuildStatus["COMPILATION_ERROR"] = "COMPILATION_ERROR";
    })(ProjectBuildStatus = DevMode.ProjectBuildStatus || (DevMode.ProjectBuildStatus = {}));
    class ProjectBuildNotificaiton extends TaonBaseClass {
        static from(json) {
            if (!_.isObject(json)) {
                return;
            }
            return new ProjectBuildNotificaiton().clone(json);
        }
        //#region is equal
        isEqual(build) {
            build = ProjectBuildNotificaiton.from(build);
            return build.uniqueKey === this.uniqueKey;
        }
        //#endregion
        get allStatusValues() {
            const values = Object.keys(this.buildStatusInfo || {})
                .filter(f => !f.includes(watcherPrefix))
                .map(key => (this.buildStatusInfo || {})[key]);
            return values;
        }
        //#region every build with status
        everyBuildsWithStatus(status) {
            if (!this.buildStatusInfo) {
                return false;
            }
            return this.allStatusValues.every(s => s === status);
        }
        //#endregion
        //#region any build with status
        anyBuildsWithStatus(status) {
            if (!this.buildStatusInfo) {
                return false;
            }
            return this.allStatusValues.some(s => s === status);
        }
        //#endregion
        get allBuildsSucceed() {
            return this.everyBuildsWithStatus(ProjectBuildStatus.DONE_BUILDING_SUCCESS);
        }
        get someBuildsFailed() {
            return this.anyBuildsWithStatus(ProjectBuildStatus.COMPILATION_ERROR);
        }
        get uniqueKey() {
            return `${this.location}__${this.nameForNpmPackage}__${this.port}`;
        }
        get isWatchBuild() {
            return this.buildType === 'watch';
        }
    }
    DevMode.ProjectBuildNotificaiton = ProjectBuildNotificaiton;
})(DevMode || (DevMode = {}));
//# sourceMappingURL=dev-mode.models.js.map