"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const StorageUtilities_1 = require("../storage/StorageUtilities");
const Log_1 = require("../core/Log");
class JigsawProcessorListDefinition {
    _file;
    _data;
    _isLoaded = false;
    get data() {
        return this._data;
    }
    get file() {
        return this._file;
    }
    set file(newFile) {
        this._file = newFile;
    }
    get isLoaded() {
        return this._isLoaded;
    }
    get id() {
        if (this._data?.["minecraft:processor_list"]?.description?.identifier) {
            return this._data["minecraft:processor_list"].description.identifier;
        }
        return "";
    }
    get processors() {
        if (this._data?.["minecraft:processor_list"]?.processors) {
            return this._data["minecraft:processor_list"].processors;
        }
        return [];
    }
    async getFormatVersionIsCurrent() {
        // For now, assume format version is current
        return true;
    }
    async addChildItems(project, item) {
        // Processor lists don't typically reference other jigsaw files directly
        // but they could reference block types, items, etc. in the future
        // For now, we'll leave this empty as processors mainly reference
        // built-in Minecraft blocks
    }
    static async ensureOnFile(file) {
        let jigsawProcessorList;
        if (file.manager === undefined) {
            jigsawProcessorList = new JigsawProcessorListDefinition();
            jigsawProcessorList.file = file;
            file.manager = jigsawProcessorList;
        }
        if (file.manager !== undefined && file.manager instanceof JigsawProcessorListDefinition) {
            jigsawProcessorList = file.manager;
            if (!jigsawProcessorList.isLoaded) {
                await jigsawProcessorList.load();
            }
        }
        return jigsawProcessorList;
    }
    async load() {
        if (this._isLoaded) {
            return;
        }
        if (this._file === undefined) {
            return;
        }
        if (!this._file.isContentLoaded) {
            await this._file.loadContent();
        }
        if (!this._file.content || this._file.content instanceof Uint8Array) {
            return;
        }
        const result = StorageUtilities_1.default.getJsonObject(this._file);
        if (result) {
            this._data = result;
        }
        this._isLoaded = true;
    }
    persist() {
        if (this._file === undefined) {
            return;
        }
        if (!this._data) {
            Log_1.default.unexpectedUndefined("ITRDP");
            return;
        }
        const dataString = JSON.stringify(this._data, null, 2);
        this._file.setContent(dataString);
    }
}
exports.default = JigsawProcessorListDefinition;

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