import { BillingProfile } from '@backend/domain'
import stripe from 'stripe'
import { BillingProfileResponse } from '../types'

export class BillingProfileMapper {
	static billingProfileToResponse(billingProfile: BillingProfile): BillingProfileResponse {
		return {
			accountId: billingProfile.stripeAccountId,
			detailsSubmitted: billingProfile.profile?.details_submitted,
			account: billingProfile.profile?.external_accounts?.data[0]
				? {
						accountHolderName:
							(billingProfile.profile.external_accounts.data[0] as stripe.BankAccount).account_holder_name ?? undefined,
						bankName: (billingProfile.profile.external_accounts.data[0] as stripe.BankAccount).bank_name ?? undefined,
						currency: billingProfile.profile.external_accounts.data[0].currency ?? undefined,
						default_for_currency: billingProfile.profile.external_accounts.data[0].default_for_currency ?? undefined,
						routing_number:
							(billingProfile.profile.external_accounts.data[0] as stripe.BankAccount).routing_number ?? undefined,
						last4: billingProfile.profile.external_accounts.data[0].last4,
					}
				: undefined,
		}
	}
}
