"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const ProjectInfoItem_1 = require("./ProjectInfoItem");
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const AddOnRequirementsGenerator_1 = require("./AddOnRequirementsGenerator");
const ResourceRenderController_1 = require("../minecraft/ResourceRenderController");
const ResourceManifestDefinition_1 = require("../minecraft/ResourceManifestDefinition");
const BehaviorManifestDefinition_1 = require("../minecraft/BehaviorManifestDefinition");
const ModelGeometryDefinition_1 = require("../minecraft/ModelGeometryDefinition");
const Material_1 = require("../minecraft/Material");
const AnimationResourceDefinition_1 = require("../minecraft/AnimationResourceDefinition");
const AnimationBehaviorDefinition_1 = require("../minecraft/AnimationBehaviorDefinition");
const AnimationControllerBehaviorDefinition_1 = require("../minecraft/AnimationControllerBehaviorDefinition");
const AnimationControllerResourceDefinition_1 = require("../minecraft/AnimationControllerResourceDefinition");
class AddOnItemRequirementsGenerator {
    constructor() {
        this.id = "ADDONIREQ";
        this.title = "Addon Item Requirements Generator";
    }
    getTopicData(topicId) {
        return {
            title: topicId.toString(),
        };
    }
    summarize(info, infoSet) { }
    async generate(projectItem, contentIndex) {
        const items = [];
        if (projectItem.itemType === IProjectItemData_1.ProjectItemType.dimensionJson) {
            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 191, `Dimension definition resources are not permitted in an add-on targeted behavior pack`, projectItem));
        }
        else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.featureBehavior) {
            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 192, `Feature definition resources are not permitted in an add-on targeted behavior pack`, projectItem));
        }
        else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.featureRuleBehaviorJson) {
            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 193, `Feature rule definition resources are not permitted in an add-on targeted behavior pack`, projectItem));
        }
        else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.resourcePackManifestJson) {
            await projectItem.ensureFileStorage();
            if (projectItem.file) {
                const rpManifest = await ResourceManifestDefinition_1.default.ensureOnFile(projectItem.file);
                if (rpManifest) {
                    await rpManifest.load();
                    if (!rpManifest.packScope) {
                        items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 140, `Resource pack manifest does not specify that header/pack_scope that should be 'world'`, projectItem));
                    }
                    if (!rpManifest.productType) {
                        items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 141, `Resource pack manifest does not specify a metadata/product_type that should be 'addon'`, projectItem));
                    }
                }
            }
        }
        else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.behaviorPackManifestJson) {
            await projectItem.ensureFileStorage();
            if (projectItem.file) {
                const bpManifest = await BehaviorManifestDefinition_1.default.ensureOnFile(projectItem.file);
                if (bpManifest) {
                    await bpManifest.load();
                    if (!bpManifest.productType) {
                        items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 142, `Behavior pack manifest does not specify a metadata/product_type that should be 'addon'`, projectItem));
                    }
                }
            }
        }
        else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.animationControllerBehaviorJson) {
            await projectItem.ensureFileStorage();
            if (projectItem.file) {
                const bacManifest = await AnimationControllerBehaviorDefinition_1.default.ensureOnFile(projectItem.file);
                if (bacManifest && bacManifest.data && bacManifest.data.animation_controllers) {
                    for (let bacName in bacManifest.data.animation_controllers) {
                        let bacNameBreak = bacName.split(".");
                        if (bacNameBreak.length < 3 || bacNameBreak[0] !== "controller" || bacNameBreak[1] !== "animation") {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 100, `Behavior pack animation controller identifier is not in expected form of controller.animation.xyz`, projectItem, bacName));
                        }
                        else if (!AddOnRequirementsGenerator_1.default.isNamespacedString(bacNameBreak[2])) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 101, `Behavior pack animation controller name section is not in expected form of controller.animation.creatorshortname_projectshortname`, projectItem, bacName));
                        }
                    }
                }
            }
        }
        else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.animationBehaviorJson) {
            await projectItem.ensureFileStorage();
            if (projectItem.file) {
                const baManifest = await AnimationBehaviorDefinition_1.default.ensureOnFile(projectItem.file);
                if (baManifest && baManifest.data && baManifest.data.animations) {
                    for (let aName in baManifest.data.animations) {
                        let baNameBreak = aName.split(".");
                        if (baNameBreak.length < 2 || baNameBreak[0] !== "animation") {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 110, `Behavior animation identifier is not in expected form of animation.xyz.animation_name`, projectItem, aName));
                        }
                        else if (!AddOnRequirementsGenerator_1.default.isNamespacedString(baNameBreak[1])) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 111, `Behavior pack animation name section is not in expected form of animation.creatorshortname_projectshortname.animation_name`, projectItem, aName));
                        }
                    }
                }
            }
        }
        else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.animationControllerResourceJson) {
            await projectItem.ensureFileStorage();
            if (projectItem.file) {
                const racManifest = await AnimationControllerResourceDefinition_1.default.ensureOnFile(projectItem.file);
                if (racManifest && racManifest.data && racManifest.data.animation_controllers) {
                    for (let racName in racManifest.data.animation_controllers) {
                        let racNameBreak = racName.split(".");
                        if (racNameBreak.length < 3 || racNameBreak[0] !== "controller" || racNameBreak[1] !== "animation") {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 120, `Resource pack animation controller identifier is not in expected form of controller.animation.xyz`, projectItem, racName));
                        }
                        else if (!AddOnRequirementsGenerator_1.default.isNamespacedString(racNameBreak[2])) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 121, `Resource pack animation controller name section is not in expected form of controller.animation.creatorshortname_projectshortname`, projectItem, racName));
                        }
                    }
                }
            }
        }
        else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.animationResourceJson) {
            await projectItem.ensureFileStorage();
            if (projectItem.file) {
                const raManifest = await AnimationResourceDefinition_1.default.ensureOnFile(projectItem.file);
                if (raManifest && raManifest.animations) {
                    for (let aName in raManifest.animations) {
                        let raNameBreak = aName.split(".");
                        if (raNameBreak.length < 2 || raNameBreak[0] !== "animation") {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 130, `Resource animation identifier is not in expected form of animation.xyz.animation_name`, projectItem, aName));
                        }
                        else if (!AddOnRequirementsGenerator_1.default.isNamespacedString(raNameBreak[1])) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 131, `Resource animation name section is not in expected form of animation.creatorshortname_projectshortname.animation_name`, projectItem, aName));
                        }
                    }
                }
            }
        }
        else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.renderControllerJson) {
            await projectItem.ensureFileStorage();
            if (projectItem.file) {
                const racManifest = await ResourceRenderController_1.default.ensureOnFile(projectItem.file);
                if (racManifest && racManifest.definition && racManifest.definition.render_controllers) {
                    for (let rrcName in racManifest.definition.render_controllers) {
                        let racNameBreak = rrcName.split(".");
                        if (racNameBreak.length < 3 || racNameBreak[0] !== "controller" || racNameBreak[1] !== "render") {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 140, `Resource pack render controller identifier is not in expected form of controller.render.creatorshortname_projectshortname.other`, projectItem, rrcName));
                        }
                        else if (!AddOnRequirementsGenerator_1.default.isNamespacedString(racNameBreak[2])) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 141, `Resource pack render controller name section is not in expected form of controller.render.creatorshortname_projectshortname`, projectItem, rrcName));
                        }
                    }
                }
            }
        }
        else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.modelGeometryJson) {
            await projectItem.ensureFileStorage();
            if (projectItem.file) {
                const modGeo = await ModelGeometryDefinition_1.default.ensureOnFile(projectItem.file);
                if (modGeo) {
                    for (const modId of modGeo.identifiers) {
                        if (modGeo && modId) {
                            let modGeoBreaks = modId.split(".");
                            if (modGeoBreaks.length < 2 || modGeoBreaks[0] !== "geometry") {
                                items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 150, `Geometry is not in expected form of geometry.creatorshortname_projectshortname.other`, projectItem, modId));
                            }
                            else if (!AddOnRequirementsGenerator_1.default.isNamespacedString(modGeoBreaks[1])) {
                                items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 151, `Geometry identifier section is not in expected form of geometry.creatorshortname_projectshortname`, projectItem, modId));
                            }
                        }
                    }
                }
            }
        }
        else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.material) {
            await projectItem.ensureFileStorage();
            if (projectItem.file) {
                const mat = await Material_1.default.ensureOnFile(projectItem.file);
                if (mat && mat.definition && mat.definition.materials) {
                    for (const modId in mat.definition.materials) {
                        let modIdBreaks = modId.split(":");
                        if (modIdBreaks.length < 1) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 160, `Materials section identifier is not in expected form of creatorshortname_projectshortname:other`, projectItem, modId));
                        }
                        else if (modIdBreaks[0] !== "version" &&
                            (!AddOnRequirementsGenerator_1.default.isNamespacedString(modIdBreaks[0]) ||
                                AddOnRequirementsGenerator_1.default.isCommonMaterialName(modIdBreaks[0]))) {
                            items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.testCompleteFail, this.id, 161, `First segment of a Materials section identifier is not in the expected form of creatorshortname_projectshortname_materialname or creatorshortname_projectshortname_materialname:baseitem`, projectItem, modId));
                        }
                    }
                }
            }
        }
        return items;
    }
}
exports.default = AddOnItemRequirementsGenerator;

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