"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveChainRegistryPath = resolveChainRegistryPath;
exports.loadOmnlChainRegistry = loadOmnlChainRegistry;
exports.getActiveChains = getActiveChains;
exports.getChainById = getChainById;
exports.getSupportedChainIds128 = getSupportedChainIds128;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
let cached = null;
function resolveChainRegistryPath() {
    if (process.env.OMNL_SUPPORTED_CHAINS_CONFIG)
        return process.env.OMNL_SUPPORTED_CHAINS_CONFIG;
    const candidates = [
        path_1.default.resolve(process.cwd(), 'config/omnl-supported-chains.v1.json'),
        path_1.default.resolve(__dirname, '../../../config/omnl-supported-chains.v1.json'),
        path_1.default.resolve(__dirname, '../../../../config/omnl-supported-chains.v1.json'),
    ];
    for (const p of candidates) {
        if (fs_1.default.existsSync(p))
            return p;
    }
    return candidates[1];
}
function loadOmnlChainRegistry() {
    if (cached)
        return cached;
    const p = resolveChainRegistryPath();
    cached = JSON.parse(fs_1.default.readFileSync(p, 'utf8'));
    return cached;
}
function getActiveChains() {
    return loadOmnlChainRegistry().chains.filter((c) => c.status === 'active');
}
function getChainById(chainId) {
    return loadOmnlChainRegistry().chains.find((c) => c.chainId === chainId);
}
function getSupportedChainIds128() {
    return loadOmnlChainRegistry().chains.map((c) => c.chainId);
}
