import { Plaid, Ribbit } from '@greenpay/models'
import { PaymentSelectors, ValidationActions } from '@greenpay/redux'

export type BankLoginProviderId = 'plaid' | 'ribbit'

export const BANK_LOGIN_ROUTE = 'bank-login'

export interface BankLoginCheckoutContext {
	getPlaid: PaymentSelectors['getPlaid']
	getRibbit: PaymentSelectors['getRibbit']
	validatePlaid: ValidationActions['validatePlaid']
	validateRibbit: ValidationActions['validateRibbit']
	getHiddenInputValue: (name: string) => string | undefined
}

export interface BankLoginClassicPayloadContext extends BankLoginCheckoutContext {
	setValue: (name: string, value: string) => void
}

export interface IBankLoginProvider {
	readonly id: BankLoginProviderId
	readonly Component: React.FC
	resolveState(ctx: BankLoginCheckoutContext): Plaid | Ribbit | null
	validate(ctx: BankLoginCheckoutContext): boolean
	buildPaymentMethodData(ctx: BankLoginCheckoutContext): Record<string, string | undefined>
	syncClassicPayload(ctx: BankLoginClassicPayloadContext): void
	clearClassicPayload(ctx: BankLoginClassicPayloadContext): void
}
