const MamiSettingsVirtualStorage = function(storage) {
    const virtuals = new Map;

    return {
        name: () => `virtual:${storage.name()}`,
        virtualise: name => virtuals.set(name, storage.get(name)),
        get: name => {
            if(virtuals.has(name))
                try {
                    return JSON.parse(virtuals.get(name));
                } catch(ex) {
                    return null;
                }

            return storage.get(name);
        },
        delete: name => {
            if(virtuals.has(name))
                virtuals.set(name, null);
            else
                storage.delete(name);
        },
        set: (name, value) => {
            if(virtuals.has(name))
                virtuals.set(name, value === undefined ? null : JSON.stringify(value));
            else
                storage.set(name, value);
        },
    };
};
