import { BankAccountStatus, bankAccountStatusFromJson, } from './BankAccountStatus'; /** * Represents an account within a saved bank account. */ export interface Account { /** The name of the account. */ accountName?: string; } /** * Creates an Account from JSON * @param json The JSON object to parse * @returns The parsed Account */ export function accountFromJson(json: any): Account { return { accountName: json.account_name, }; } /** * Converts an Account to its JSON representation * @param account The account to convert * @returns The JSON object */ export function accountToJson(account: Account): any { return { account_name: account.accountName, }; } /** * SavedBankAccount is an interface that represents a saved bank account method. * * Use Cases: * - Managing and displaying saved bank account information. * - Allowing users to select from previously saved bank account methods. */ export interface SavedBankAccount { /** The unique identifier for the saved bank account. */ id?: string; /** The bank identifier or code. */ bankIdentifier?: string; /** The logo URL or identifier for the bank. */ logo?: string; /** The status of the saved bank account. */ status?: BankAccountStatus; /** An array of accounts associated with this saved bank account. */ accounts?: Account[]; /** The type of the method, set to "savedBankAccount". */ type: 'savedBankAccount'; /** The title or name of the saved bank account method. */ title?: string; /** A boolean indicating whether the saved bank account method is selected. */ isSelected?: boolean; /** An array of icons associated with the saved bank account method. */ checkoutIcons?: string[]; } /** * Creates a SavedBankAccount from JSON * @param json The JSON object to parse * @returns The parsed SavedBankAccount */ export function savedBankAccountFromJson(json: any): SavedBankAccount { return { id: json.id, bankIdentifier: json.bank_identifier, logo: json.logo, status: json.status ? bankAccountStatusFromJson(json.status) : undefined, accounts: json.accounts ? json.accounts.map(accountFromJson) : undefined, type: 'savedBankAccount', title: json.bank_identifier, isSelected: json.is_selected, checkoutIcons: json.logo ? [json.logo] : undefined, }; } /** * Converts a SavedBankAccount to its JSON representation * @param savedBankAccount The saved bank account to convert * @returns The JSON object */ export function savedBankAccountToJson( savedBankAccount: SavedBankAccount ): any { return { id: savedBankAccount.id, bank_identifier: savedBankAccount.bankIdentifier, logo: savedBankAccount.logo, status: savedBankAccount.status, accounts: savedBankAccount.accounts ? savedBankAccount.accounts.map(accountToJson) : undefined, type: savedBankAccount.type, is_selected: savedBankAccount.isSelected, }; }