import { TaonBaseClass } from 'taon/lib-prod';
import { ___NS__isObject } from 'tnp-core/lib-prod';
import { watcherPrefix } from '../../../../constants';
//namespace DevMode
export const DevMode__NS__MAX_NUMBER_OF_CONCURENT_BUILDS = 1;
export var DevMode__NS__ProjectBuildStatus;
(function (DevMode__NS__ProjectBuildStatus) {
    /**
     * External command to cancel build (TODO implement killing of processes)
     */
    DevMode__NS__ProjectBuildStatus["__CANCEL_BUILD__"] = "__CANCEL_BUILD__";
    /**
     * External command to start building (or repeat build if build active)
     */
    DevMode__NS__ProjectBuildStatus["__START_BUILD__"] = "__START_BUILD__";
    /**
     * 1. default state of porject
     */
    DevMode__NS__ProjectBuildStatus["NOT_STARTED"] = "NOT_STARTED";
    /**
     * Each project is immediatlly building because of BehaviorSubject()
     */
    DevMode__NS__ProjectBuildStatus["BUILDING"] = "BUILDING";
    /**
     * Cancelled build of project (but still building - I am not killing processes)
     */
    DevMode__NS__ProjectBuildStatus["BUILDING_BUT_CANCELLED"] = "BUILDING_BUT_CANCELLED";
    /**
     * Auto rebuild of project at the end of building
     */
    DevMode__NS__ProjectBuildStatus["BUILDING_WITH_REBUILD_AT_THE_END"] = "BUILDING_WITH_REBUILD_AT_THE_END";
    /**
     * Done building
     */
    DevMode__NS__ProjectBuildStatus["DONE_BUILDING_SUCCESS"] = "DONE_BUILDING_SUCCESS";
    /**
     * Cancelled build of project (process idle)
     */
    DevMode__NS__ProjectBuildStatus["BUILD_CANCEL_DONE"] = "BUILD_CANCEL_DONE";
    /**
     * Build error.
     */
    DevMode__NS__ProjectBuildStatus["COMPILATION_ERROR"] = "COMPILATION_ERROR";
})(DevMode__NS__ProjectBuildStatus || (DevMode__NS__ProjectBuildStatus = {}));
export class DevMode__NS__ProjectBuildNotificaiton extends TaonBaseClass {
    static from(json) {
        if (!___NS__isObject(json)) {
            return;
        }
        return new DevMode__NS__ProjectBuildNotificaiton().clone(json);
    }
    //#region is equal
    isEqual(build) {
        build = DevMode__NS__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(DevMode__NS__ProjectBuildStatus.DONE_BUILDING_SUCCESS);
    }
    get someBuildsFailed() {
        return this.anyBuildsWithStatus(DevMode__NS__ProjectBuildStatus.COMPILATION_ERROR);
    }
    get uniqueKey() {
        return `${this.location}__${this.nameForNpmPackage}__${this.port}`;
    }
    get isWatchBuild() {
        return this.buildType === 'watch';
    }
}
//end of namespace DevMode
//# sourceMappingURL=dev-mode.models.js.map