const MamiSettingsScoped = function(settings, prefix) {
    if(typeof settings !== 'object')
        throw 'settings must be an object';
    if(typeof prefix !== 'string')
        throw 'prefix must be a string';
    if(prefix.length < 1)
        throw 'prefix may not be empty';

    if(!prefix.endsWith(':'))
        prefix += ':';

    return {
        define: name => settings.define(prefix + name),
        defined: name => settings.defined(prefix + name),
        info: name => settings.info(prefix + name),
        names: () => {
            const filtered = [];
            const names = settings.names();

            for(const name in names)
                if(name.startsWith(prefix))
                    filtered.push(name.substring(prefix.length));

            return filtered;
        },
        has: name => settings.has(prefix + name),
        get: name => settings.get(prefix + name),
        set: (name, value, silent) => settings.set(prefix + name, value, silent),
        delete: (name, silent) => settings.delete(prefix + name, silent),
        toggle: (name, silent) => settings.toggle(prefix + name, silent),
        touch: (name, silent) => settings.touch(prefix + name, silent),
        clear: (criticalOnly, pfx) => settings.clear(criticalOnly, prefix + pfx),
        watch: (name, handler, silent) => settings.watch(prefix + name, handler, silent),
        unwatch: (name, handler) => settings.unwatch(prefix + name, handler),
        virtualise: name => settings.virtualise(prefix + name),
        scope: name => settings.scope(prefix + name),
    };
};
