export type TypeNetworkDetails = {
  name: string;
  chainId: number;
  shortName: string;
  chain: string;
  networkId: number;
  nativeCurrency: { name: string; symbol: string; decimals: number };
  rpc: string[];
  faucets: string[];
  explorers: { name: string; url: string; standard: string };
  infoURL: string;
  logoURL: string;
  collateralizedContractAddresses: string[];
  collateralFreeContractAddresses: string[];
  revenueSharedNFTRentalsContractAddresses: string[];
  revenueSharedConfiguratorContractAddresses: string[];
  e721ContractAddresses: string[];
  e721BContractAddresses: string[];
  e1155ContractAddresses: string[];
  e1155BContractAddresses: string[];
  wETHContractAddresses: string[];
  daiContractAddresses: string[];
  usdcContractAddresses: string[];
  usdtContractAddresses: string[];
  tUSDContractAddresses: string[];
  utilsContractAddresses: string[];
  subgraphs: {
    collateralized: string;
    collateralFree: string;
    revenueSharedNFTRentals: string;
    e721: string;
    e1155: string;
  };
  moralisDetails: { isSupported: boolean; lookupValue: string };
  chainApiId: string;
  isSupported: boolean;
  isTestnet: boolean;
};

export type TypeNetworkConfig = {
  [key: string]: TypeNetworkDetails;
};

/// Value must be same as abi's "Bytecode" file name
export enum ContractType {
  COLLATERALIZED = 'Collateralized',
  COLLATERAL_FREE = 'CollateralFree',
  REVENUE_SHARE = 'RevenueShare',
  REVENUE_SHARED_CONFIGURATOR = 'RevenueSharedConfigurator',
  E721 = 'E721',
  E721_B = 'E721B',
  E1155 = 'E1155',
  E1155_B = 'E1155B',
  WETH = 'WETH',
  DAI = 'DAI',
  USDC = 'USDC',
  USDT = 'USDT',
  T_USD = 'TUSD',
  UTILS = 'Utils',
}

export const CONTRACT_TYPE_LIST: ContractType[] = Object.values(
  ContractType
).filter(id => typeof id === 'string') as ContractType[];

export enum SupportedChainIds {
  ETHEREUM_MAINNET = 1,
  ETHEREUM_ROPSTEN = 3,
  ETHEREUM_RINKEBY = 4,
  ETHEREUM_KOVAN = 42,

  BINANCE_MAINNET = 56,
  BINANCE_TESTNET = 97,

  POLYGON_MAINNET = 137,
  POLYGON_TESTNET = 80001,
}

export const ALL_SUPPORTED_CHAIN_IDS: SupportedChainIds[] = Object.values(
  SupportedChainIds
).filter(id => typeof id === 'number') as SupportedChainIds[];

/// Note:
/// 1.  Contract address array version priority [Vn....3,2,1] (Latest contract at zero index)
export const NetworkConfig: TypeNetworkConfig = {
  [SupportedChainIds.ETHEREUM_MAINNET]: {
    name: 'Ethereum Mainnet',
    chainId: 1,
    shortName: 'eth',
    chain: 'ETH',
    networkId: 1,
    nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
    rpc: [
      'https://mainnet.infura.io/v3/${INFURA_API_KEY}',
      'wss://mainnet.infura.io/ws/v3/${INFURA_API_KEY}',
      'https://api.mycryptoapi.com/eth',
      'https://cloudflare-eth.com',
    ],
    faucets: [],
    explorers: {
      name: 'etherscan',
      url: 'https://etherscan.io',
      standard: 'EIP3091',
    },
    infoURL: 'https://ethereum.org',
    logoURL: '/assets/images/chain-logos/ethereum-logo.png',
    collateralizedContractAddresses: [],
    collateralFreeContractAddresses: [],
    revenueSharedNFTRentalsContractAddresses: [],
    revenueSharedConfiguratorContractAddresses: [],
    e721ContractAddresses: [],
    e721BContractAddresses: [],
    e1155ContractAddresses: [],
    e1155BContractAddresses: [],
    wETHContractAddresses: [],
    daiContractAddresses: [],
    usdcContractAddresses: [],
    usdtContractAddresses: [],
    tUSDContractAddresses: [],
    utilsContractAddresses: [],
    subgraphs: {
      collateralized: '',
      collateralFree: '',
      revenueSharedNFTRentals: '',
      e721: '',
      e1155: '',
    },
    moralisDetails: { isSupported: true, lookupValue: 'eth' },
    chainApiId: 'binancecoin',
    isSupported: false,
    isTestnet: false,
  },
  [SupportedChainIds.ETHEREUM_ROPSTEN]: {
    name: 'Ethereum Testnet Ropsten',
    chainId: 3,
    shortName: 'rop',
    chain: 'ETH-Testnet',
    networkId: 3,
    nativeCurrency: {
      name: 'Ropsten Ether',
      symbol: 'ROP',
      decimals: 18,
    },
    rpc: [
      'https://ropsten.infura.io/v3/${INFURA_API_KEY}',
      'wss://ropsten.infura.io/ws/v3/${INFURA_API_KEY}',
    ],
    faucets: ['https://faucet.ropsten.be?${ADDRESS}'],
    explorers: {
      name: 'etherscan-ropsten',
      url: 'https://ropsten.etherscan.io/',
      standard: 'EIP3091',
    },
    infoURL: 'https://github.com/ethereum/ropsten',
    logoURL: '/assets/images/chain-logos/ethereum-logo.png',
    collateralizedContractAddresses: [],
    collateralFreeContractAddresses: [],
    revenueSharedNFTRentalsContractAddresses: [],
    revenueSharedConfiguratorContractAddresses: [],
    e721ContractAddresses: [],
    e721BContractAddresses: [],
    e1155ContractAddresses: [],
    e1155BContractAddresses: [],
    wETHContractAddresses: [],
    daiContractAddresses: [],
    usdcContractAddresses: [],
    usdtContractAddresses: [],
    tUSDContractAddresses: [],
    utilsContractAddresses: [],
    subgraphs: {
      collateralized: '',
      collateralFree: '',
      revenueSharedNFTRentals: '',
      e721: '',
      e1155: '',
    },
    moralisDetails: { isSupported: false, lookupValue: '' },
    chainApiId: 'binancecoin',
    isSupported: false,
    isTestnet: true,
  },
  [SupportedChainIds.ETHEREUM_RINKEBY]: {
    name: 'Ethereum Testnet Rinkeby',
    chainId: 4,
    shortName: 'rin',
    chain: 'ETH-Testnet',
    networkId: 4,
    nativeCurrency: {
      name: 'Rinkeby Ether',
      symbol: 'RIN',
      decimals: 18,
    },
    rpc: [
      'https://rinkeby.infura.io/v3/${INFURA_API_KEY}',
      'wss://rinkeby.infura.io/ws/v3/${INFURA_API_KEY}',
    ],
    faucets: ['https://faucet.rinkeby.io'],
    explorers: {
      name: 'etherscan-rinkeby',
      url: 'https://rinkeby.etherscan.io',
      standard: 'EIP3091',
    },
    infoURL: 'https://www.rinkeby.io',
    logoURL: '/assets/images/chain-logos/ethereum-logo.png',
    collateralizedContractAddresses: [],
    collateralFreeContractAddresses: [],
    revenueSharedNFTRentalsContractAddresses: [],
    revenueSharedConfiguratorContractAddresses: [],
    e721ContractAddresses: [],
    e721BContractAddresses: [],
    e1155ContractAddresses: [],
    e1155BContractAddresses: [],
    wETHContractAddresses: [],
    daiContractAddresses: [],
    usdcContractAddresses: [],
    usdtContractAddresses: [],
    tUSDContractAddresses: [],
    utilsContractAddresses: [],
    subgraphs: {
      collateralized: '',
      collateralFree: '',
      revenueSharedNFTRentals: '',
      e721: '',
      e1155: '',
    },
    moralisDetails: { isSupported: false, lookupValue: '' },
    chainApiId: 'binancecoin',
    isSupported: false,
    isTestnet: true,
  },
  [SupportedChainIds.ETHEREUM_KOVAN]: {
    name: 'Kovan Testnet',
    chainId: 42,
    shortName: 'KOV',
    chain: 'kovan',
    networkId: 42,
    nativeCurrency: { name: 'Kovan', symbol: 'KOV', decimals: 18 },
    rpc: [
      'https://kovan.poa.network',
      'http://kovan.poa.network:8545',
      'https://kovan.infura.io/v3/${INFURA_API_KEY}',
      'wss://kovan.infura.io/ws/v3/${INFURA_API_KEY}',
      'ws://kovan.poa.network:8546',
    ],
    faucets: [
      'https://faucet.kovan.network',
      'https://gitter.im/kovan-testnet/faucet',
    ],
    explorers: {
      name: 'etherscan-kovan',
      url: 'https://kovan.etherscan.io/',
      standard: 'EIP3091',
    },
    infoURL: 'https://kovan-testnet.github.io/website',
    logoURL: '/assets/images/chain-logos/kovan-logo-svg.svg',
    collateralizedContractAddresses: [
      '0xc4E1142e0dcF1CBdDcD101Bd6C82DB5bDc946C6e',
    ],
    collateralFreeContractAddresses: [
      '0x0948a02CCf44949C3853Cb087698C91C9E37Dddd',
    ],
    revenueSharedNFTRentalsContractAddresses: [],
    revenueSharedConfiguratorContractAddresses: [
      '0x3A92F1c74D4F10b9eb3E12C890E55663F510F8a5',
    ],
    e721ContractAddresses: ['0xD3b55Bf4A849992AA52f2293CDDb493A18b980Dd'],
    e721BContractAddresses: ['0x4EF6d4f83341AAF584DB7599ba7BCB0f29CdC51A'],
    e1155ContractAddresses: ['0xBFBA01C44c6f36EB7f8b6e805c969d1F438fF650'],
    e1155BContractAddresses: ['0xE9397bDf06a56303e0159f1D618Efde7E90dA3A3'],
    wETHContractAddresses: ['0xe74ffdF419f30aD24dDe778d7317Ba7d3BB18f4a'],
    daiContractAddresses: ['0x45793Ad70378a863922706f465eCbC26f4c195f9'],
    usdcContractAddresses: ['0x3ebBC74E7579F800fE8C3d058377b95c06f7f0e1'],
    usdtContractAddresses: ['0xAA92036d1D11f4120E9345E990072e868B48Be7e'],
    tUSDContractAddresses: ['0xeFEfAC77461FF56Ff26F3Db522e42AbEA7aE38b5'],
    utilsContractAddresses: ['0xAe79A95cCeFDEb13584e7595d4FCC8D3cAac352a'],
    subgraphs: {
      collateralized:
        'https://kovan.infy.network/subgraphs/name/infy-collateralized/subgraph',
      collateralFree:
        'https://kovan.infy.network/subgraphs/name/infy-collateral-free/subgraph',
      revenueSharedNFTRentals: '',
      e721:
        'https://kovan.infy.network/subgraphs/name/wighawag/eip721-subgraph',
      e1155: 'https://kovan.infy.network/subgraphs/name/amxx/eip1155-subgraph',
    },
    moralisDetails: { isSupported: false, lookupValue: '' },
    chainApiId: 'kovan-testnet',
    isSupported: false,
    isTestnet: true,
  },
  [SupportedChainIds.BINANCE_MAINNET]: {
    name: 'BSC Smart Chain Mainnet',
    chainId: 56,
    shortName: 'bnb',
    chain: 'BSC',

    networkId: 56,
    nativeCurrency: {
      name: 'Binance Chain Native Token',
      symbol: 'BNB',
      decimals: 18,
    },
    rpc: [
      'https://bsc-dataseed1.binance.org',
      'https://bsc-dataseed2.binance.org',
      'https://bsc-dataseed3.binance.org',
      'https://bsc-dataseed4.binance.org',
      'https://bsc-dataseed1.defibit.io',
      'https://bsc-dataseed2.defibit.io',
      'https://bsc-dataseed3.defibit.io',
      'https://bsc-dataseed4.defibit.io',
      'https://bsc-dataseed1.ninicoin.io',
      'https://bsc-dataseed2.ninicoin.io',
      'https://bsc-dataseed3.ninicoin.io',
      'https://bsc-dataseed4.ninicoin.io',
      'wss://bsc-ws-node.nariox.org',
    ],
    faucets: [],
    explorers: {
      name: 'bscscan',
      url: 'https://bscscan.com',
      standard: 'EIP3091',
    },
    infoURL: 'https://www.binance.org',
    logoURL: '/assets/images/chain-logos/binance-logo.png',
    collateralizedContractAddresses: [],
    collateralFreeContractAddresses: [],
    revenueSharedNFTRentalsContractAddresses: [],
    revenueSharedConfiguratorContractAddresses: [],
    e721ContractAddresses: [],
    e721BContractAddresses: [],
    e1155ContractAddresses: [],
    e1155BContractAddresses: [],
    wETHContractAddresses: [],
    daiContractAddresses: [],
    usdcContractAddresses: [],
    usdtContractAddresses: [],
    tUSDContractAddresses: [],
    utilsContractAddresses: [],
    subgraphs: {
      collateralized: '',
      collateralFree: '',
      revenueSharedNFTRentals: '',
      e721: '',
      e1155: '',
    },
    moralisDetails: { isSupported: true, lookupValue: 'bsc' },
    chainApiId: 'binancecoin',
    isSupported: false,
    isTestnet: false,
  },
  [SupportedChainIds.BINANCE_TESTNET]: {
    name: 'BSC Smart Chain Testnet',
    chainId: 97,
    shortName: 'bnbt',
    chain: 'BSC-Testnet',
    networkId: 97,
    nativeCurrency: {
      name: 'Binance Chain Native Token',
      symbol: 'BNB',
      decimals: 18,
    },
    rpc: [
      'https://data-seed-prebsc-2-s1.binance.org:8545',
      'https://data-seed-prebsc-1-s1.binance.org:8545',
      'https://data-seed-prebsc-1-s2.binance.org:8545',
      'https://data-seed-prebsc-2-s2.binance.org:8545',
      'https://data-seed-prebsc-1-s3.binance.org:8545',
      'https://data-seed-prebsc-2-s3.binance.org:8545',
    ],
    faucets: ['https://testnet.binance.org/faucet-smart'],
    explorers: {
      name: 'bscscan-testnet',
      url: 'https://testnet.bscscan.com',
      standard: 'EIP3091',
    },
    infoURL: 'https://testnet.binance.org/',
    logoURL: '/assets/images/chain-logos/binance-logo.png',
    collateralizedContractAddresses: [],
    collateralFreeContractAddresses: [],
    revenueSharedNFTRentalsContractAddresses: [],
    revenueSharedConfiguratorContractAddresses: [],
    e721ContractAddresses: [],
    e721BContractAddresses: [],
    e1155ContractAddresses: [],
    e1155BContractAddresses: [],
    wETHContractAddresses: [],
    daiContractAddresses: [],
    usdcContractAddresses: [],
    usdtContractAddresses: [],
    tUSDContractAddresses: [],
    utilsContractAddresses: [],
    subgraphs: {
      collateralized: '',
      collateralFree: '',
      revenueSharedNFTRentals: '',
      e721: '',
      e1155: '',
    },
    moralisDetails: { isSupported: true, lookupValue: 'bsc testnet' },
    chainApiId: 'binancecoin',
    isSupported: false,
    isTestnet: true,
  },
  [SupportedChainIds.POLYGON_MAINNET]: {
    name: 'Polygon',
    chainId: 137,
    shortName: 'Polygon',
    chain: 'Polygon',
    networkId: 137,
    nativeCurrency: { name: 'Matic', symbol: 'MATIC', decimals: 18 },
    rpc: [
      'https://rpc-mainnet.matic.network',
      'wss://ws-mainnet.matic.network',
    ],
    faucets: [],
    explorers: {
      name: 'polygonscan',
      url: 'https://polygonscan.com',
      standard: 'EIP3091',
    },
    infoURL: 'https://matic.network/',
    logoURL: '/assets/images/chain-logos/matic-logo-svg.svg',
    collateralizedContractAddresses: [
      '0xCf311a6606c909Cc5E048FE1f3FF1e63dEec6a26',
    ],
    collateralFreeContractAddresses: [
      '0x4fF4C17F24d03Faf9d5097D7E71310AeF71a0f70',
    ],
    revenueSharedNFTRentalsContractAddresses: [
      '0x9C5dA47ED0281aF302ED1E77a1B961ed980d5385',
    ],
    revenueSharedConfiguratorContractAddresses: [
      '0x4a1BDD3a5BBAb4312432b1b507d67Bce6baC8B22',
    ],
    e721ContractAddresses: [],
    e721BContractAddresses: [],
    e1155ContractAddresses: [],
    e1155BContractAddresses: [],
    wETHContractAddresses: ['0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619'],
    daiContractAddresses: ['0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063'],
    usdcContractAddresses: ['0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174'],
    usdtContractAddresses: ['0xc2132D05D31c914a87C6611C10748AEb04B58e8F'],
    tUSDContractAddresses: ['0x2e1AD108fF1D8C782fcBbB89AAd783aC49586756'],
    utilsContractAddresses: [],
    subgraphs: {
      collateralized:
        'https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-collateralized-polygon',
      collateralFree:
        'https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-collateral-free-polygon',
      revenueSharedNFTRentals:
        'https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-revenue-share-polygon',
      e721: '',
      e1155: '',
    },
    moralisDetails: { isSupported: true, lookupValue: 'polygon' },
    chainApiId: 'matic-network',
    isSupported: true,
    isTestnet: false,
  },
  [SupportedChainIds.POLYGON_TESTNET]: {
    name: 'Mumbai-Testnet',
    chainId: 80001,
    shortName: 'Mumbai',
    chain: 'Mumbai-TestNet',
    networkId: 80001,
    nativeCurrency: { name: 'Matic', symbol: 'MATIC', decimals: 18 },
    rpc: ['https://rpc-mumbai.matic.today', 'wss://ws-mumbai.matic.today'],
    faucets: ['https://faucet.matic.network/'],
    explorers: {
      name: 'mumbai-polygonscan',
      url: 'https://mumbai.polygonscan.com/',
      standard: 'EIP3091',
    },
    infoURL: 'https://matic.network/',
    logoURL: '/assets/images/chain-logos/matic-logo-svg.svg',
    collateralizedContractAddresses: [
      '0xDA0b94C237b435cbeA5Dd5aD44cc6F235aaE5855',
    ],
    collateralFreeContractAddresses: [
      '0x8f5138FDe08Be9061612086f4bCA472a563544c4',
    ],
    revenueSharedNFTRentalsContractAddresses: [
      '0x9352a6007F186c11FBC1daBc9fFFFA62Ea9eb9f3',
    ],
    revenueSharedConfiguratorContractAddresses: [
      '0x418258c4412bC13b3C877374BCE70890d456Cc1e',
    ],
    e721ContractAddresses: ['0x1506aF09A9a0D9179008d5F3E778ba46B76B54bc'],
    e721BContractAddresses: ['0xAe79A95cCeFDEb13584e7595d4FCC8D3cAac352a'],
    e1155ContractAddresses: ['0xd742C9Dd714c6FD0dB880Ed278e7Dc3e472fABb5'],
    e1155BContractAddresses: ['0x3A92F1c74D4F10b9eb3E12C890E55663F510F8a5'],
    wETHContractAddresses: ['0xAA92036d1D11f4120E9345E990072e868B48Be7e'],
    daiContractAddresses: ['0xeFEfAC77461FF56Ff26F3Db522e42AbEA7aE38b5'],
    usdcContractAddresses: ['0xD3b55Bf4A849992AA52f2293CDDb493A18b980Dd'],
    usdtContractAddresses: ['0x4EF6d4f83341AAF584DB7599ba7BCB0f29CdC51A'],
    tUSDContractAddresses: ['0x4bC7EA42aE5E5D4F8Dab60646B247978EEF09888'],
    utilsContractAddresses: ['0xb6A0B7e204E86823eB78689e50a6Ed10931583B5'],
    subgraphs: {
      collateralized:
        'https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-collateralized-mumbai',
      collateralFree:
        'https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-collateral-free-mumbai',
      revenueSharedNFTRentals:
        'https://api.thegraph.com/subgraphs/name/dudhatparesh/infy-revenue-share-mumbai',
      e721: '',
      e1155: '',
    },
    moralisDetails: { isSupported: true, lookupValue: 'mumbai' },
    chainApiId: 'matic-network',
    isSupported: true,
    isTestnet: true,
  },
};

export const GetNetworkDetailsByChainId = (
  networkId: SupportedChainIds
): TypeNetworkDetails => {
  return NetworkConfig[networkId];
};
