"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get flattenOctoPrintFiles () {
        return flattenOctoPrintFiles;
    },
    get normalizePrinterFile () {
        return normalizePrinterFile;
    }
});
function normalizePrinterFile(file) {
    if (!file) {
        throw new Error("File should not be null for normalization");
    }
    const keys = Object.keys(file);
    const fileCopy = {
        ...file
    };
    const knownKeys = [
        "path",
        "date",
        "hash",
        "size"
    ];
    const unknownKeys = keys.filter((k)=>!knownKeys.includes(k));
    const customData = {};
    for (const unknownKey of unknownKeys){
        customData[unknownKey] = fileCopy[unknownKey];
        delete fileCopy[unknownKey];
    }
    return {
        path: fileCopy.path,
        size: fileCopy.size,
        date: fileCopy.date,
        dir: fileCopy.type === 'folder'
    };
}
function flattenOctoPrintFiles(items, parentPath = '') {
    const files = [];
    for (const item of items){
        const fullPath = parentPath ? `${parentPath}/${item.name}` : item.name;
        if (item.type === 'folder') {
            files.push({
                path: fullPath,
                size: 0,
                date: item.date || null,
                dir: true
            });
            if (item.children) {
                files.push(...flattenOctoPrintFiles(item.children, fullPath));
            }
        } else if (item.type === 'machinecode') {
            files.push({
                path: fullPath,
                size: item.size,
                date: item.date,
                dir: false
            });
        }
    }
    return files;
}

//# sourceMappingURL=file.utils.js.map