"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Config = exports.ConfigService = void 0;
const config_1 = __importDefault(require("../config"));
const utils_1 = require("../utils");
class ConfigService {
    constructor({ _config = config_1.default } = {}) {
        this._config = _config;
    }
    get() {
        return this._config;
    }
    updateConfig(partialConfig) {
        const newConfig = Object.assign({}, this.get(), partialConfig);
        this._config = newConfig;
    }
    chains() {
        return Object.keys(this.get().chains);
    }
    networksFor(chain) {
        return Object.keys(this.get().chains[chain]);
    }
    chainNetworks() {
        const chainNetworks = new Array();
        for (const chain of this.chains()) {
            for (const network of this.networksFor(chain)) {
                chainNetworks.push({ chain, network });
            }
        }
        return chainNetworks;
    }
    chainConfig({ chain, network }) {
        return this.get().chains[chain][network];
    }
    for(service) {
        return this.get().services[service] || {};
    }
    isDisabled(service) {
        const serviceConfig = this.for(service);
        const isDefined = x => x !== undefined;
        const disabled = isDefined(serviceConfig) ? (0, utils_1.valueOrDefault)(serviceConfig.disabled, false) : false;
        return disabled;
    }
    aliasFor({ chain, network }) {
        let aliasChain = chain;
        let aliasNetwork = network;
        const aliasMapping = this.get().aliasMapping;
        if (aliasMapping.chains[chain]) {
            aliasChain = aliasMapping.chains[chain];
        }
        if (aliasMapping.networks[aliasChain]?.[network]) {
            aliasNetwork = aliasMapping.networks[aliasChain][network];
        }
        return { chain: aliasChain, network: aliasNetwork };
    }
}
exports.ConfigService = ConfigService;
exports.Config = new ConfigService();
//# sourceMappingURL=config.js.map