import { mainnet } from 'wagmi/chains'
import type { Address } from 'viem'
import { TRUSTLESS } from './bridge'
import { chain138 as chain138Network, chain2138Testnet } from './networks'

// Contract addresses on Ethereum Mainnet and Chain 138
// Trustless bridge (Lockbox, Inbox, LP, Coordinators, ChallengeManager) — use TRUSTLESS from bridge.ts as single source of truth
export const CONTRACT_ADDRESSES = {
  mainnet: {
    MAINNET_TETHER: '0x15DF1D5BFDD8Aa4b380445D4e3E9B38d34283619' as Address,
    TRANSACTION_MIRROR: '0x4CF42c4F1dBa748601b8938be3E7ABD732E87cE9' as Address,
    PAYMENT_CHANNEL_MANAGER: undefined as Address | undefined,
    GENERIC_STATE_CHANNEL_MANAGER: undefined as Address | undefined,
    TWOWAY_BRIDGE_L1: undefined as Address | undefined,
    INBOX_ETH: TRUSTLESS.mainnet.INBOX_ETH as Address,
    LIQUIDITY_POOL: TRUSTLESS.mainnet.LIQUIDITY_POOL as Address,
    BRIDGE_SWAP_COORDINATOR: TRUSTLESS.mainnet.BRIDGE_SWAP_COORDINATOR as Address,
    DUAL_ROUTER_BRIDGE_SWAP_COORDINATOR: TRUSTLESS.mainnet.DUAL_ROUTER_BRIDGE_SWAP_COORDINATOR as Address,
    CHALLENGE_MANAGER: TRUSTLESS.mainnet.CHALLENGE_MANAGER as Address,
  },
  chain138: {
    TRANSACTION_MIRROR: '0xE362aa10D3Af1A16880A799b78D18F923403B55a' as Address,
    PAYMENT_CHANNEL_MANAGER: undefined as Address | undefined,
    GENERIC_STATE_CHANNEL_MANAGER: undefined as Address | undefined,
    TWOWAY_BRIDGE_L2: undefined as Address | undefined,
    LOCKBOX_138: TRUSTLESS.chain138.LOCKBOX_138 as Address,
  },
  chain2138: {
    TRANSACTION_MIRROR: (import.meta.env.VITE_TRANSACTION_MIRROR_CHAIN2138 || undefined) as Address | undefined,
    PAYMENT_CHANNEL_MANAGER: undefined as Address | undefined,
    GENERIC_STATE_CHANNEL_MANAGER: undefined as Address | undefined,
    TWOWAY_BRIDGE_L2: undefined as Address | undefined,
    LOCKBOX_2138: TRUSTLESS.chain2138.LOCKBOX_2138 as Address,
  },
} as const

export { TRUSTLESS } from './bridge'

// Chain 138 for wagmi (custom chain)
export const chain138 = {
  ...chain138Network,
} as const

export const chain2138 = {
  ...chain2138Testnet,
} as const

export const SUPPORTED_CHAINS = {
  mainnet,
  chain138,
  chain2138,
} as const
