"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const IProjectItemData_1 = require("../app/IProjectItemData");
const AnimationBehaviorDefinition_1 = require("./AnimationBehaviorDefinition");
const AnimationControllerBehaviorDefinition_1 = require("./AnimationControllerBehaviorDefinition");
const AnimationControllerResourceDefinition_1 = require("./AnimationControllerResourceDefinition");
const AnimationResourceDefinition_1 = require("./AnimationResourceDefinition");
const AudioDefinition_1 = require("./AudioDefinition");
const BehaviorManifestDefinition_1 = require("./BehaviorManifestDefinition");
const BiomeBehaviorDefinition_1 = require("./BiomeBehaviorDefinition");
const BiomeResourceDefinition_1 = require("./BiomeResourceDefinition");
const BlockTypeDefinition_1 = require("./BlockTypeDefinition");
const EntityTypeDefinition_1 = require("./EntityTypeDefinition");
const EntityTypeResourceDefinition_1 = require("./EntityTypeResourceDefinition");
const FlipbookTextureCatalogDefinition_1 = require("./FlipbookTextureCatalogDefinition");
const ItemTypeDefinition_1 = require("./ItemTypeDefinition");
const JigsawProcessorListDefinition_1 = require("./JigsawProcessorListDefinition");
const JigsawStructureDefinition_1 = require("./JigsawStructureDefinition");
const JigsawStructureSetDefinition_1 = require("./JigsawStructureSetDefinition");
const JigsawTemplatePoolDefinition_1 = require("./JigsawTemplatePoolDefinition");
const MusicDefinitionCatalogDefinition_1 = require("./MusicDefinitionCatalogDefinition");
const RenderControllerSetDefinition_1 = require("./RenderControllerSetDefinition");
const ResourceManifestDefinition_1 = require("./ResourceManifestDefinition");
const SoundCatalogDefinition_1 = require("./SoundCatalogDefinition");
const SoundDefinitionCatalogDefinition_1 = require("./SoundDefinitionCatalogDefinition");
class MinecraftDefinitions {
    static async get(projectItem) {
        if (!projectItem.isContentLoaded) {
            await projectItem.loadContent();
        }
        if (!projectItem.primaryFile ||
            !projectItem.primaryFile.content ||
            typeof projectItem.primaryFile.content !== "string") {
            if (!projectItem.primaryFile) {
                return undefined;
            }
            if (!projectItem.primaryFile.isContentLoaded) {
                await projectItem.primaryFile.loadContent();
            }
            if (!projectItem.primaryFile.content || typeof projectItem.primaryFile.content !== "string") {
                return undefined;
            }
        }
        switch (projectItem.itemType) {
            case IProjectItemData_1.ProjectItemType.entityTypeBehavior:
                return await EntityTypeDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.entityTypeResource:
                return await EntityTypeResourceDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.itemTypeBehavior:
                return await ItemTypeDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.blockTypeBehavior:
                return await BlockTypeDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.flipbookTexturesJson:
                return await FlipbookTextureCatalogDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.behaviorPackManifestJson:
                return await BehaviorManifestDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.resourcePackManifestJson:
                return await ResourceManifestDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.animationControllerBehaviorJson:
                return await AnimationControllerBehaviorDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.animationControllerResourceJson:
                return await AnimationControllerResourceDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.animationBehaviorJson:
                return await AnimationBehaviorDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.animationResourceJson:
                return await AnimationResourceDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.soundDefinitionCatalog:
                return await SoundDefinitionCatalogDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.soundCatalog:
                return await SoundCatalogDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.musicDefinitionJson:
                return await MusicDefinitionCatalogDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.renderControllerJson:
                return await RenderControllerSetDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.biomeBehavior:
                return await BiomeBehaviorDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.biomeResource:
                return await BiomeResourceDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.jigsawProcessorList:
                return await JigsawProcessorListDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.jigsawStructureSet:
                return await JigsawStructureSetDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.jigsawTemplatePool:
                return await JigsawTemplatePoolDefinition_1.default.ensureOnFile(projectItem.primaryFile);
            case IProjectItemData_1.ProjectItemType.jigsawStructure:
                return await JigsawStructureDefinition_1.default.ensureOnFile(projectItem.primaryFile);
        }
        return undefined;
    }
    static async ensureFoundationalDependencies(item) {
        if (item.itemType === IProjectItemData_1.ProjectItemType.audio) {
            if (!item.isContentLoaded) {
                await item.loadContent();
            }
            if (item.primaryFile) {
                const audioFile = await AudioDefinition_1.default.ensureOnFile(item.primaryFile);
                if (audioFile) {
                    await audioFile.ensureSoundDefinitionsForFile(item.project);
                }
            }
        }
    }
    static async formatVersionIsCurrent(projectItem) {
        const def = await MinecraftDefinitions.get(projectItem);
        if (def && def.getFormatVersionIsCurrent) {
            return await def.getFormatVersionIsCurrent();
        }
        return true;
    }
    static async getFormatVersion(projectItem) {
        const def = await MinecraftDefinitions.get(projectItem);
        if (def && def.getFormatVersion) {
            const fv = await def.getFormatVersion();
            if (!(fv instanceof Array)) {
                return undefined;
            }
            return fv;
        }
        return undefined;
    }
}
exports.default = MinecraftDefinitions;

//# sourceMappingURL=../maps/minecraft/MinecraftDefinitions.js.map
