"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable frontApplet/enforce-jsdoc */
const generator_1 = require("../../Hash/generator");
class AppendFlagController {
    loadFile;
    name = 'append';
    elementCache;
    constructor(loadFile) {
        this.loadFile = loadFile;
        this.elementCache = {};
    }
    create(element) {
        const uid = (0, generator_1.generateUniqueHash)();
        this.elementCache[uid] = element;
        return {
            type: 'append',
            element: {
                uid,
            },
        };
    }
    async applyFlag(flag, fileType, filePath) {
        if (typeof flag.element !== 'object') {
            throw new Error('File flag of type "append" needs to be object');
        }
        const element = this.elementCache[flag.element.uid];
        if (typeof element === 'undefined') {
            throw new Error('File flag element for "append" not found');
        }
        const loadFileController = this.loadFile[fileType];
        if (typeof loadFileController === 'undefined') {
            throw new Error('File of type "' + fileType + '" cannot be appent');
        }
        await loadFileController.load(filePath, element);
    }
}
exports.default = AppendFlagController;
//# sourceMappingURL=AppendFlagController.js.map