const config = require('config');

function Settings() {

    this.getOrThrow = function (key, context) {

        context = context || "configuration";
        const value = this.getOrDefault(key);
        if (!value)
            throw new Error("Unknown " + context + ": " + key);

        return value;
    };

    this.getOrDefault = function (key, defaultValue) {

        const value = config.has(key) ? config.get(key) : undefined;
        return value ? config.util.cloneDeep(value) : defaultValue;
    };
}

module.exports = Settings;