using Managing.Common;
using Managing.Domain.Evm;

namespace Managing.Infrastructure.Evm.Services;

public static class ChainService
{
    //private const string RPC_ARBITRUM = "https://convincing-smart-arm.arbitrum-mainnet.discover.quiknode.pro/561ad3fa1db431a2c728c2fdb1a62e8f94acf703/";
    private const string RPC_ARBITRUM =
        "https://arb1.arbitrum.io/rpc";

    private const string RPC_ARBITRUM_GOERLI = "https://arb-goerli.g.alchemy.com/v2/ZMkIiKtNvgY03UtWOjho0oqkQrNt_pyc";
    private const string RPC_ETHEREUM = "https://mainnet.infura.io/v3/58f44d906ab345beadd03dd2b76348af";
    private const string RPC_ETHEREUM_GOERLI = "https://eth-goerli.g.alchemy.com/v2/xbc-eM-vxBmM9Uf1-RjjGjLp8Ng-FIc6";

    public static Chain GetChain(string chainName)
    {
        if (string.IsNullOrEmpty(chainName))
            throw new Exception("Chain name is null or empty");

        return GetChains().FirstOrDefault(c => c.Name == chainName);
    }

    public static List<Chain> GetChains()
    {
        var chains = new List<Chain>()
        {
            GetArbitrum(),
            GetEthereum(),
            //GetArbitrumGoerli(),
            //GetGoerli()
        };

        return chains;
    }

    public static Chain GetArbitrum()
    {
        return new Chain()
        {
            Name = Constants.Chains.Arbitrum,
            RpcUrl = RPC_ARBITRUM,
            ChainId = 42161
        };
    }

    public static Chain GetEthereum()
    {
        return new Chain()
        {
            Name = Constants.Chains.Ethereum,
            RpcUrl = RPC_ETHEREUM,
            ChainId = 1
        };
    }

    public static Chain GetArbitrumGoerli()
    {
        return new Chain()
        {
            Name = Constants.Chains.ArbitrumGoerli,
            RpcUrl = RPC_ARBITRUM_GOERLI
        };
    }

    public static Chain GetGoerli()
    {
        return new Chain()
        {
            Name = Constants.Chains.Goerli,
            RpcUrl = RPC_ETHEREUM_GOERLI
        };
    }
}