"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypesInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = require("./ProjectInfoItem");
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const ContentIndex_1 = require("../core/ContentIndex");
const ProjectInfoUtilities_1 = require("./ProjectInfoUtilities");
const EntityTypeDefinition_1 = require("../minecraft/EntityTypeDefinition");
const BlockTypeDefinition_1 = require("../minecraft/BlockTypeDefinition");
const ItemTypeDefinition_1 = require("../minecraft/ItemTypeDefinition");
const BlocksCatalogDefinition_1 = require("../minecraft/BlocksCatalogDefinition");
var TypesInfoGeneratorTest;
(function (TypesInfoGeneratorTest) {
    TypesInfoGeneratorTest[TypesInfoGeneratorTest["types"] = 101] = "types";
})(TypesInfoGeneratorTest = exports.TypesInfoGeneratorTest || (exports.TypesInfoGeneratorTest = {}));
class TypesInfoGenerator {
    id = "TYPES";
    title = "Types Info Aggregation";
    performAddOnValidations = false;
    getTopicData(topicId) {
        return {
            title: ProjectInfoUtilities_1.default.getTitleFromEnum(TypesInfoGeneratorTest, topicId),
        };
    }
    summarize(info, infoSet) {
        info.textureCount = infoSet.getSummedDataValue(this.id, TypesInfoGeneratorTest.types);
    }
    async generate(project, contentIndex) {
        const items = [];
        const typesCountPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, TypesInfoGeneratorTest.types, "Types");
        items.push(typesCountPi);
        const itemsCopy = project.getItemsCopy();
        for (const projectItem of itemsCopy) {
            if (projectItem.itemType === IProjectItemData_1.ProjectItemType.entityTypeBehavior) {
                if (!projectItem.isContentLoaded) {
                    await projectItem.loadContent();
                }
                if (projectItem.primaryFile) {
                    const etd = await EntityTypeDefinition_1.default.ensureOnFile(projectItem.primaryFile);
                    if (etd && etd.id && projectItem.projectPath) {
                        contentIndex.insert(etd.id, projectItem.projectPath, ContentIndex_1.AnnotationCategory.entityTypeSource);
                    }
                }
            }
            else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.blockTypeBehavior) {
                if (!projectItem.isContentLoaded) {
                    await projectItem.loadContent();
                }
                if (projectItem.primaryFile) {
                    const blockTypeDef = await BlockTypeDefinition_1.default.ensureOnFile(projectItem.primaryFile);
                    if (blockTypeDef && blockTypeDef.id && projectItem.projectPath) {
                        contentIndex.insert(blockTypeDef.id, projectItem.projectPath, ContentIndex_1.AnnotationCategory.blockTypeSource);
                        let colon = blockTypeDef.id.indexOf(":");
                        if (colon >= 0) {
                            contentIndex.insert(blockTypeDef.id.substring(colon + 1), projectItem.projectPath, ContentIndex_1.AnnotationCategory.blockTypeSource);
                        }
                    }
                }
            }
            else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.blocksCatalogResourceJson) {
                if (!projectItem.isContentLoaded) {
                    await projectItem.loadContent();
                }
                if (projectItem.primaryFile) {
                    const blockCatalog = await BlocksCatalogDefinition_1.default.ensureOnFile(projectItem.primaryFile);
                    if (blockCatalog && projectItem.projectPath && blockCatalog.blocksCatalog) {
                        for (const name in blockCatalog.blocksCatalog) {
                            let adjustedName = name;
                            let colon = adjustedName.indexOf(":");
                            if (colon < 0 && project.isVanillaSourceProject) {
                                adjustedName = "minecraft:" + adjustedName;
                                contentIndex.insert(adjustedName, projectItem.projectPath, ContentIndex_1.AnnotationCategory.blockTypeSource);
                            }
                            contentIndex.insert(name, projectItem.projectPath, ContentIndex_1.AnnotationCategory.blockTypeSource);
                        }
                    }
                }
            }
            else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.itemTypeBehavior) {
                if (!projectItem.isContentLoaded) {
                    await projectItem.loadContent();
                }
                if (projectItem.primaryFile) {
                    const itemTypeDef = await ItemTypeDefinition_1.default.ensureOnFile(projectItem.primaryFile);
                    if (itemTypeDef && itemTypeDef.id && projectItem.projectPath) {
                        contentIndex.insert(itemTypeDef.id, projectItem.projectPath, ContentIndex_1.AnnotationCategory.itemTypeSource);
                    }
                }
            }
        }
        return items;
    }
}
exports.default = TypesInfoGenerator;

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