"use strict";
/*
 * @poppinss/utils
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManagerConfigValidator = void 0;
const Exception_1 = require("./Exception");
/**
 * A simple class to raise consistent exceptions for invalid config
 * for driver based implementations.
 */
class ManagerConfigValidator {
    constructor(config, serviceName, configLocation) {
        this.config = config;
        this.serviceName = serviceName;
        this.configLocation = configLocation;
    }
    /**
     * Validates that the default key name is defined inside the config
     * for a given module/service
     */
    validateDefault(keyName) {
        if (!this.config[keyName]) {
            throw new Exception_1.Exception([
                `Invalid "${this.serviceName}" config. Missing value for "${keyName}".`,
                `Make sure to set it inside the "${this.configLocation}" file`,
            ].join(' '));
        }
    }
    /**
     * Validates that the list to ensure that is is defined and the default
     * key name is also part of the list.
     */
    validateList(listName, keyName) {
        if (!this.config[listName]) {
            throw new Exception_1.Exception([
                `Invalid "${this.serviceName}" config. Missing value for "${listName}".`,
                `Make sure to set it inside the "${this.configLocation}" file`,
            ].join(' '));
        }
        const defaultValue = this.config[keyName];
        if (!this.config[listName][defaultValue]) {
            throw new Exception_1.Exception([
                `Invalid "${this.serviceName}" config. "${defaultValue}" is not defined inside "${listName}".`,
                `Make sure to set it inside the "${this.configLocation}" file`,
            ].join(' '));
        }
    }
}
exports.ManagerConfigValidator = ManagerConfigValidator;
