import { zip } from "../utils";
import { constMap } from "../utils/mapping";
// prettier-ignore
const chainIdAndChainEntries = [
    //Unlike the old sdk, we are not including an "Unset" chain with chainId 0 here because:
    //  * no other types would be associated with it (such as contracts or a platform)
    //  * avoids awkward "chain but not 'Unset'" checks
    //  * "off" is not a TV channel either
    //Instead we'll use `null` for chain and 0 as the chainId where appropriate (e.g. governance VAAs)
    [1, "Solana"],
    [2, "Ethereum"],
    [3, "Terra"],
    [4, "Bsc"],
    [5, "Polygon"],
    [6, "Avalanche"],
    [7, "Oasis"],
    [8, "Algorand"],
    [9, "Aurora"],
    [10, "Fantom"],
    [11, "Karura"],
    [12, "Acala"],
    [13, "Klaytn"],
    [14, "Celo"],
    [15, "Near"],
    [16, "Moonbeam"],
    [17, "Neon"],
    [18, "Terra2"],
    [19, "Injective"],
    [20, "Osmosis"],
    [21, "Sui"],
    [22, "Aptos"],
    [23, "Arbitrum"],
    [24, "Optimism"],
    [25, "Gnosis"],
    [26, "Pythnet"],
    [28, "Xpla"],
    [29, "Btc"],
    [30, "Base"],
    [32, "Sei"],
    [33, "Rootstock"],
    [3104, "Wormchain"],
    [4000, "Cosmoshub"],
    [4001, "Evmos"],
    [4002, "Kujira"],
    [10002, "Sepolia"],
    [10003, "ArbitrumSepolia"],
    [10004, "BaseSepolia"],
    [10005, "OptimismSepolia"],
    [10006, "Holesky"],
];
export const [chainIds, chains] = zip(chainIdAndChainEntries);
export const chainToChainId = constMap(chainIdAndChainEntries, [1, 0]);
export const chainIdToChain = constMap(chainIdAndChainEntries);
export const isChain = (chain) => chainToChainId.has(chain);
export const isChainId = (chainId) => chainIdToChain.has(chainId);
export function assertChainId(chainId) {
    if (!isChainId(chainId))
        throw Error(`Unknown Wormhole chain id: ${chainId}`);
}
export function assertChain(chain) {
    if (!isChain(chain))
        throw Error(`Unknown Wormhole chain: ${chain}`);
}
//safe assertion that allows chaining
export const asChainId = (chainId) => {
    assertChainId(chainId);
    return chainId;
};
export const toChainId = (chain) => {
    switch (typeof chain) {
        case "string":
            if (isChain(chain))
                return chainToChainId(chain);
            break;
        case "number":
            if (isChainId(chain))
                return chain;
            break;
    }
    throw Error(`Cannot convert to ChainId: ${chain}`);
};
export const toChain = (chain) => {
    switch (typeof chain) {
        case "string":
            if (isChain(chain))
                return chain;
            break;
        case "number":
            if (isChainId(chain))
                return chainIdToChain(chain);
            break;
        case "bigint":
            if (isChainId(Number(chain)))
                return chainIdToChain(Number(chain));
            break;
    }
    throw Error(`Cannot convert to Chain: ${chain}`);
};
//# sourceMappingURL=chains.js.map