import { plaidBankLoginProvider } from './plaid.provider'
import { ribbitBankLoginProvider } from './ribbit.provider'
import { BankLoginProviderId, IBankLoginProvider } from './types'

const bankLoginProviders: Record<BankLoginProviderId, IBankLoginProvider> = {
	plaid: plaidBankLoginProvider,
	ribbit: ribbitBankLoginProvider,
}

export const bankLoginProviderList: IBankLoginProvider[] = Object.values(bankLoginProviders)

export function normalizeBankLoginProviderId(id?: string | null): BankLoginProviderId {
	return id === 'plaid' ? 'plaid' : 'ribbit'
}

export function getBankLoginProvider(id?: string | null): IBankLoginProvider {
	return bankLoginProviders[normalizeBankLoginProviderId(id)]
}

export function isBankLoginMethod(method: string | null | undefined): method is BankLoginProviderId {
	return method === 'plaid' || method === 'ribbit'
}

export function getBankLoginProviderByMethod(method: string | null | undefined): IBankLoginProvider | null {
	return isBankLoginMethod(method) ? getBankLoginProvider(method) : null
}
