"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.SummaryInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = require("./ProjectInfoItem");
const ProjectItemUtilities_1 = require("../app/ProjectItemUtilities");
const MinecraftUtilities_1 = require("../minecraft/MinecraftUtilities");
const Constants_1 = require("../core/Constants");
const IProjectItemData_1 = require("../app/IProjectItemData");
const ResourceManifestDefinition_1 = require("../minecraft/ResourceManifestDefinition");
const BehaviorManifestDefinition_1 = require("../minecraft/BehaviorManifestDefinition");
const IInfoItemData_1 = require("./IInfoItemData");
var SummaryInfoGeneratorTest;
(function (SummaryInfoGeneratorTest) {
    SummaryInfoGeneratorTest[SummaryInfoGeneratorTest["resourceManifest"] = 101] = "resourceManifest";
    SummaryInfoGeneratorTest[SummaryInfoGeneratorTest["behaviorManifest"] = 102] = "behaviorManifest";
})(SummaryInfoGeneratorTest = exports.SummaryInfoGeneratorTest || (exports.SummaryInfoGeneratorTest = {}));
class SummaryInfoGenerator {
    id = "SUMMARY";
    title = "Summary Information";
    canAlwaysProcess = true;
    performAddOnValidations = false;
    getTopicData(topicId) {
        return {
            title: "",
        };
    }
    summarize(info, infoSet) {
        info.mctoolsVersion = MinecraftUtilities_1.default.getVersionNumber(Constants_1.constants.version);
        let typesInUse = [];
        const typesInUseSet = new Set();
        const resourceFeatureMeasures = infoSet.getFeaturesWithInstances(this.id, SummaryInfoGeneratorTest.resourceManifest);
        for (const resourceFeatureMeasure of resourceFeatureMeasures) {
            if (resourceFeatureMeasure === "pbr") {
                info.capabilities.push("vvcompat");
            }
            if (!info.capabilities.includes(resourceFeatureMeasure)) {
                info.capabilities.push(resourceFeatureMeasure);
            }
        }
        const behaviorFeatureMeasures = infoSet.getFeaturesWithInstances(this.id, SummaryInfoGeneratorTest.behaviorManifest);
        for (const behaviorFeatureMeasure of behaviorFeatureMeasures) {
            if (!info.capabilities.includes(behaviorFeatureMeasure)) {
                info.capabilities.push(behaviorFeatureMeasure);
            }
        }
        if (infoSet.project) {
            const itemsCopy = infoSet.project.getItemsCopy();
            for (const item of itemsCopy) {
                const typeDesc = ProjectItemUtilities_1.default.getDescriptionForType(item.itemType);
                if (item.itemType === IProjectItemData_1.ProjectItemType.behaviorPackManifestJson) {
                    if (!info.capabilities.includes("behaviorPack")) {
                        info.capabilities.push("behaviorPack");
                    }
                }
                else if (item.itemType === IProjectItemData_1.ProjectItemType.resourcePackManifestJson) {
                    if (!info.capabilities.includes("resourcePack")) {
                        info.capabilities.push("resourcePack");
                    }
                }
                else if (item.itemType === IProjectItemData_1.ProjectItemType.skinPackManifestJson) {
                    if (!info.capabilities.includes("skinPack")) {
                        info.capabilities.push("skinPack");
                    }
                }
                else if (item.itemType === IProjectItemData_1.ProjectItemType.js) {
                    if (!info.capabilities.includes("scripting")) {
                        info.capabilities.push("scripting");
                    }
                }
                else if (item.itemType === IProjectItemData_1.ProjectItemType.tickJson) {
                    if (!info.capabilities.includes("tickJson")) {
                        info.capabilities.push("tickJson");
                    }
                }
                else if (item.itemType === IProjectItemData_1.ProjectItemType.MCFunction) {
                    if (!info.capabilities.includes("functions")) {
                        info.capabilities.push("functions");
                    }
                }
                else if (item.itemType === IProjectItemData_1.ProjectItemType.animationBehaviorJson) {
                    if (!info.capabilities.includes("behaviorAnimations")) {
                        info.capabilities.push("behaviorAnimations");
                    }
                }
                else if (ProjectItemUtilities_1.default.isVibrantVisualsRelated(item)) {
                    if (!info.capabilities.includes("vvfiles")) {
                        info.capabilities.push("vvfiles");
                    }
                }
                if (!typesInUseSet.has(typeDesc)) {
                    typesInUse.push(typeDesc);
                    typesInUseSet.add(typeDesc);
                }
            }
        }
        typesInUse.sort();
        info.itemTypes = typesInUse;
    }
    // this should run after every other summarize pass has happened.
    summarizePhase2(info, infoSet) {
        let hasCameraJson = false;
        if (infoSet.project) {
            for (const item of infoSet.project.items) {
                if (item.itemType === IProjectItemData_1.ProjectItemType.cameraBehaviorJson) {
                    hasCameraJson = true;
                    break; // Early exit once found
                }
            }
        }
        const commands = info.commands;
        const apisUsed = info.apisUsed;
        const capabilitiesSet = new Set(info.capabilities);
        if (hasCameraJson || commands.includes("camera") || apisUsed.includes("setCamera")) {
            if (!capabilitiesSet.has("camera")) {
                info.capabilities.push("camera");
            }
        }
        info.capabilities.sort();
    }
    async generate(project, contentIndex) {
        const itemsCopy = project.getItemsCopy();
        const items = [];
        const resourceManifestPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, SummaryInfoGeneratorTest.resourceManifest, "Resource Manifests");
        items.push(resourceManifestPi);
        const behaviorManifestPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, SummaryInfoGeneratorTest.behaviorManifest, "Behavior Manifests");
        items.push(behaviorManifestPi);
        for (const item of itemsCopy) {
            if (item.itemType === IProjectItemData_1.ProjectItemType.behaviorPackManifestJson) {
                const manifestFile = item.primaryFile;
                if (!manifestFile) {
                    continue;
                }
                const manifest = await BehaviorManifestDefinition_1.default.ensureOnFile(manifestFile);
                if (!manifest) {
                    continue;
                }
                if (manifest.capabilities) {
                    for (const capability of manifest.capabilities) {
                        behaviorManifestPi.incrementFeature(capability);
                    }
                }
            }
            else if (item.itemType === IProjectItemData_1.ProjectItemType.resourcePackManifestJson) {
                const manifestFile = item.primaryFile;
                if (!manifestFile) {
                    continue;
                }
                const manifest = await ResourceManifestDefinition_1.default.ensureOnFile(manifestFile);
                if (!manifest) {
                    continue;
                }
                if (manifest.capabilities) {
                    for (const capability of manifest.capabilities) {
                        resourceManifestPi.incrementFeature(capability);
                    }
                }
            }
        }
        return items;
    }
}
exports.default = SummaryInfoGenerator;

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