/*
 * Copyright (c) 2022 @automata-network/wallet-sdk authors and contributors.
 * This software may be modified and distributed under the terms of UNLICENSED
 * license. Refer to the LICENSE file for details.
 */
import { createContext } from 'react'

import { ApiPromise } from '@polkadot/api'
import { WalletContextState } from '@solana/wallet-adapter-react'
import { ethers } from 'ethers'

import { AtaWalletState, Chains } from '../../core/interfaces'

export interface WalletContextProps {
  appName?: string
  account?: string
  chainId?: string
  chainName?: string
  chains: Chains
  walletState?: AtaWalletState
  ethersProvider?: ethers.providers.Web3Provider
  solanaWallet?: WalletContextState
  polkadotApi?: ApiPromise
  loading: boolean
  prefixCls?: string
  theme?: 'light' | 'dark'
  connect: (chainId: string) => Promise<void>
  disconnect: () => Promise<void>
  switchChain: (chainId: string) => Promise<void>
}

export const WalletContext = createContext<WalletContextProps>({
  appName: undefined,
  account: undefined,
  chainId: undefined,
  chainName: undefined,
  chains: [],
  walletState: undefined,
  ethersProvider: undefined,
  polkadotApi: undefined,
  loading: true,
  connect: async () => {
    throw new Error('connect function must be overriden before use')
  },
  disconnect: async () => {
    throw new Error('disconnect function must be overriden before use')
  },
  switchChain: async () => {
    throw new Error('switchChain function must be overriden before use')
  }
})
