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, type, fallback, immutable, critical) => settings.define(prefix + name, type, fallback, immutable, critical),
        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) => settings.set(prefix + name, value),
        delete: name => settings.delete(prefix + name),
        toggle: name => settings.toggle(prefix + name),
        touch: name => settings.touch(prefix + name),
        clear: (criticalOnly, pfx) => settings.clear(criticalOnly, prefix + pfx),
        watch: (name, handler) => settings.watch(prefix + name, handler),
        unwatch: (name, handler) => settings.unwatch(prefix + name, handler),
        virtualise: name => settings.virtualise(prefix + name),
        scope: name => settings.scope(prefix + name),
    };
};
