"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadM2TokenRegistry = loadM2TokenRegistry;
exports.loadExchangeTokens = loadExchangeTokens;
exports.loadExchangeConfig = loadExchangeConfig;
exports.exchangePort = exchangePort;
exports.tokenAggUrl = tokenAggUrl;
exports.settlementUrl = settlementUrl;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const settlement_core_1 = require("@dbis/settlement-core");
let cached = null;
let cachedM2 = null;
function loadM2TokenRegistry() {
    if (cachedM2)
        return cachedM2;
    const p = process.env.OMNL_M2_TOKEN_REGISTRY ||
        path_1.default.resolve(__dirname, '../../../config/omnl-m2-token-registry.v1.json');
    cachedM2 = JSON.parse(fs_1.default.readFileSync(p, 'utf8'));
    return cachedM2;
}
function loadExchangeTokens() {
    const cfg = loadExchangeConfig();
    return (0, settlement_core_1.mergeExchangeTokensWithM2Registry)(cfg.tokens, loadM2TokenRegistry());
}
function loadExchangeConfig() {
    if (cached)
        return cached;
    const p = process.env.DBIS_EXCHANGE_CONFIG ||
        path_1.default.resolve(__dirname, '../../../config/dbis-exchange.v1.json');
    cached = JSON.parse(fs_1.default.readFileSync(p, 'utf8'));
    return cached;
}
function exchangePort() {
    return parseInt(process.env.DBIS_EXCHANGE_PORT || '3012', 10);
}
function tokenAggUrl() {
    return (process.env.TOKEN_AGGREGATION_URL || 'http://localhost:3000').replace(/\/$/, '');
}
function settlementUrl() {
    return (process.env.SETTLEMENT_MIDDLEWARE_URL || 'http://localhost:3011').replace(/\/$/, '');
}
