"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.PackType = void 0;
const BehaviorManifestDefinition_1 = require("./BehaviorManifestDefinition");
const ResourceManifestDefinition_1 = require("./ResourceManifestDefinition");
const SkinManifestDefinition_1 = require("./SkinManifestDefinition");
const PersonaManifestDefinition_1 = require("./PersonaManifestDefinition");
var PackType;
(function (PackType) {
    PackType[PackType["resource"] = 0] = "resource";
    PackType[PackType["behavior"] = 1] = "behavior";
    PackType[PackType["skin"] = 2] = "skin";
    PackType[PackType["persona"] = 3] = "persona";
    PackType[PackType["design"] = 4] = "design";
})(PackType = exports.PackType || (exports.PackType = {}));
class Pack {
    type;
    manifestFile;
    folder;
    project;
    projectItem;
    manifest;
    constructor(folderIn, packTypeIn, project, projectItem) {
        this.project = project;
        this.projectItem = projectItem;
        this.folder = folderIn;
        this.type = packTypeIn;
    }
    ensureManifestFile() {
        if (this.manifestFile === undefined) {
            this.manifestFile = this.folder.ensureFile("manifest.json");
        }
        return this.manifestFile;
    }
    async ensureManifest() {
        if (this.manifest) {
            return this.manifest;
        }
        this.manifestFile = this.ensureManifestFile();
        if (this.type === PackType.behavior) {
            this.manifest = await BehaviorManifestDefinition_1.default.ensureOnFile(this.manifestFile);
        }
        else if (this.type === PackType.skin) {
            this.manifest = await SkinManifestDefinition_1.default.ensureOnFile(this.manifestFile);
        }
        else if (this.type === PackType.persona) {
            this.manifest = await PersonaManifestDefinition_1.default.ensureOnFile(this.manifestFile);
        }
        else if (this.type === PackType.design) {
            this.manifest = await PersonaManifestDefinition_1.default.ensureOnFile(this.manifestFile);
        }
        else {
            this.manifest = await ResourceManifestDefinition_1.default.ensureOnFile(this.manifestFile);
        }
        return this.manifest;
    }
    getPackItems() {
        const folderPath = this.projectItem.projectPath;
        if (!folderPath) {
            throw new Error("Pack.getPackItems called without a project path");
        }
        return this.project.items.filter((item) => item.projectPath?.startsWith(folderPath));
    }
    static ensureOnFolder(folder, packType, project, projectItem) {
        if (folder.manager === undefined) {
            const pack = new Pack(folder, packType, project, projectItem);
            pack.project = project;
            pack.type = packType;
            return pack;
        }
        else {
            return folder.manager;
        }
    }
    get name() {
        return this.projectItem?.name || "Unnamed pack";
    }
    async getFiles(predicate) {
        const result = [];
        for await (const file of this.folder.allFiles) {
            await file.loadContent();
            if (file.content && (!predicate || predicate(file))) {
                result.push(file);
            }
        }
        return result;
    }
}
exports.default = Pack;

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