"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m") throw new TypeError("Private method is not writable");
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _ProjectInfoItem_data, _ProjectInfoItem_projectItem;
Object.defineProperty(exports, "__esModule", { value: true });
const Utilities_1 = require("../core/Utilities");
const MinecraftUtilities_1 = require("../minecraft/MinecraftUtilities");
const IInfoItemData_1 = require("./IInfoItemData");
class ProjectInfoItem {
    get dataObject() {
        return __classPrivateFieldGet(this, _ProjectInfoItem_data, "f");
    }
    get itemType() {
        return __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").iTp;
    }
    get message() {
        return __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").m;
    }
    set message(newMessage) {
        __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").m = newMessage;
    }
    get generatorId() {
        return __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").gId;
    }
    get generatorIndex() {
        return __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").gIx;
    }
    get projectItem() {
        return __classPrivateFieldGet(this, _ProjectInfoItem_projectItem, "f");
    }
    get data() {
        return __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").d;
    }
    set data(data) {
        __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").d = data;
    }
    get content() {
        return __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").c;
    }
    get featureSets() {
        return __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs;
    }
    get contentSummary() {
        let errorContent = __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").c;
        if (errorContent) {
            errorContent = errorContent.replace(/\n/gi, " ");
            errorContent = errorContent.replace(/\r/gi, " ");
            if (errorContent.length > 80) {
                errorContent = errorContent.substring(0, 77) + "...";
            }
        }
        return errorContent;
    }
    disconnect() {
        __classPrivateFieldSet(this, _ProjectInfoItem_projectItem, undefined, "f");
    }
    get typeSummary() {
        switch (__classPrivateFieldGet(this, _ProjectInfoItem_data, "f").iTp) {
            case IInfoItemData_1.InfoItemType.info:
                return "Info";
            case IInfoItemData_1.InfoItemType.warning:
                return "Warning";
            case IInfoItemData_1.InfoItemType.recommendation:
                return "Recommendation";
            case IInfoItemData_1.InfoItemType.featureAggregate:
                return "Feature aggregation";
            case IInfoItemData_1.InfoItemType.testCompleteFail:
                return "Test fail";
            case IInfoItemData_1.InfoItemType.testCompleteSuccess:
                return "Test success";
            case IInfoItemData_1.InfoItemType.error:
                return "Error";
            default:
                return "Unknown";
        }
    }
    get projectItemPath() {
        if (this.projectItem) {
            return this.projectItem.projectPath;
        }
        else if (__classPrivateFieldGet(this, _ProjectInfoItem_data, "f").p) {
            return __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").p;
        }
        return undefined;
    }
    get shortProjectItemPath() {
        if (this.projectItem && this.projectItem.projectPath) {
            return MinecraftUtilities_1.default.getAfterPackPath(this.projectItem.projectPath);
        }
        else if (__classPrivateFieldGet(this, _ProjectInfoItem_data, "f").p) {
            return MinecraftUtilities_1.default.getAfterPackPath(__classPrivateFieldGet(this, _ProjectInfoItem_data, "f").p);
        }
        return undefined;
    }
    get typeSummaryShort() {
        let short = this.typeSummary.toUpperCase();
        short = short.replace(/\s/g, "");
        return short;
    }
    toString() {
        let summaryString = this.typeSummaryShort + ": ";
        summaryString += "[" + this.generatorId + Utilities_1.default.frontPadToLength(this.generatorIndex, 3, "0") + "] ";
        if (this.projectItem) {
            summaryString += "(" + this.projectItem.projectPath + ") ";
        }
        else if (__classPrivateFieldGet(this, _ProjectInfoItem_data, "f").p) {
            summaryString += "(" + __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").p + ") ";
        }
        if (this.message) {
            summaryString += this.message;
        }
        if (this.data) {
            summaryString += ": " + this.data;
        }
        const errorContent = this.contentSummary;
        if (errorContent) {
            summaryString += " [in " + errorContent + "]";
        }
        return summaryString;
    }
    minFeature(setName, measureName, newValue) {
        if (__classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs === undefined) {
            __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs = {};
        }
        let setVal = __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs[setName];
        if (setVal === undefined) {
            setVal = {};
            __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs[setName] = setVal;
        }
        let curVal = setVal[measureName];
        if (curVal === undefined) {
            curVal = newValue;
        }
        else {
            curVal = Math.min(curVal, newValue);
        }
        setVal[measureName] = curVal;
    }
    maxFeature(setName, measureName, newValue) {
        if (__classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs === undefined) {
            __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs = {};
        }
        let setVal = __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs[setName];
        if (setVal === undefined) {
            setVal = {};
            __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs[setName] = setVal;
        }
        let curVal = setVal[measureName];
        if (curVal === undefined) {
            curVal = newValue;
        }
        else {
            curVal = Math.max(curVal, newValue);
        }
        setVal[measureName] = curVal;
    }
    getFeatureContaining(token) {
        token = token.toLowerCase();
        for (const setName in __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs) {
            const featureSet = __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs[setName];
            if (featureSet) {
                for (const measureName in featureSet) {
                    if (measureName.toLowerCase().indexOf(token) >= 0) {
                        return featureSet[measureName];
                    }
                }
            }
        }
        return undefined;
    }
    spectrumFeature(setName, newValue) {
        if (__classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs === undefined) {
            __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs = {};
        }
        this.incrementFeature(setName, "Instance Count", 1);
        this.incrementFeature(setName, "Total", newValue);
        this.maxFeature(setName, "Max", newValue);
        this.minFeature(setName, "Min", newValue);
        let setVal = __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs[setName];
        if (setVal === undefined) {
            setVal = {};
            __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs[setName] = setVal;
        }
        const curTotal = setVal["Total"];
        const curCount = setVal["Instance Count"];
        if (curCount && curTotal !== undefined) {
            setVal["Average"] = curTotal / curCount;
        }
    }
    spectrumIntFeature(setName, newValue) {
        if (__classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs === undefined) {
            __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs = {};
        }
        let setVal = __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs[setName];
        if (setVal === undefined) {
            setVal = {};
            __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs[setName] = setVal;
        }
        this.incrementFeature(setName, "Instance Count", 1);
        this.incrementFeature(setName, "Total", newValue);
        this.maxFeature(setName, "Max", newValue);
        this.minFeature(setName, "Min", newValue);
        const curTotal = setVal["Total"];
        const curCount = setVal["Instance Count"];
        if (curCount && curTotal !== undefined) {
            setVal["Average"] = Math.round(curTotal / curCount);
        }
    }
    incrementFeature(setName, measureName, incrementalValue) {
        if (__classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs === undefined) {
            __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs = {};
        }
        if (measureName === undefined) {
            measureName = "Count";
        }
        if (incrementalValue === 0) {
            incrementalValue = 0;
        }
        else if (incrementalValue === undefined) {
            incrementalValue = 1;
        }
        let setVal = __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs[setName];
        if (setVal === undefined) {
            setVal = {};
            __classPrivateFieldGet(this, _ProjectInfoItem_data, "f").fs[setName] = setVal;
        }
        let curVal = setVal[measureName];
        if (!curVal) {
            curVal = incrementalValue;
        }
        else {
            curVal += incrementalValue;
        }
        setVal[measureName] = curVal;
    }
    constructor(itemType, generatorId, generatorIndex, message, projectItem, data, itemId, content, projectItemPath) {
        _ProjectInfoItem_data.set(this, void 0);
        _ProjectInfoItem_projectItem.set(this, void 0);
        __classPrivateFieldSet(this, _ProjectInfoItem_data, {
            iTp: itemType,
            gId: generatorId,
            gIx: generatorIndex,
            m: message,
            p: projectItem ? projectItem.projectPath : projectItemPath,
            d: data,
            iId: itemId,
            c: content,
            fs: undefined,
        }, "f");
        __classPrivateFieldSet(this, _ProjectInfoItem_projectItem, projectItem, "f");
    }
}
exports.default = ProjectInfoItem;
_ProjectInfoItem_data = new WeakMap(), _ProjectInfoItem_projectItem = new WeakMap();

//# sourceMappingURL=../maps/info/ProjectInfoItem.js.map
