'use client'; import type { GetLeagueWalletOutputDTO } from '@/lib/types/generated/GetLeagueWalletOutputDTO'; import type { LeagueWalletViewData } from '@/lib/view-data/LeagueWalletViewData'; import type { WalletTransactionViewData } from '@/lib/view-data/WalletTransactionViewData'; import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder'; import { NumberFormatter } from '@/lib/formatters/NumberFormatter'; type LeagueWalletInputDTO = GetLeagueWalletOutputDTO & { leagueId: string; } export class LeagueWalletViewDataBuilder { public static build(apiDto: LeagueWalletInputDTO): LeagueWalletViewData { const transactions: WalletTransactionViewData[] = (apiDto.transactions || []).map(t => ({ id: t.id, type: t.type as WalletTransactionViewData['type'], description: t.description, amount: t.amount, fee: t.fee, netAmount: t.netAmount, date: t.date, status: t.status as WalletTransactionViewData['status'], reference: t.reference, })); return { leagueId: apiDto.leagueId, balance: apiDto.balance || 0, formattedBalance: NumberFormatter.formatCurrency(apiDto.balance || 0, apiDto.currency), totalRevenue: apiDto.totalRevenue || 0, formattedTotalRevenue: NumberFormatter.formatCurrency(apiDto.totalRevenue || 0, apiDto.currency), totalFees: apiDto.totalFees || 0, formattedTotalFees: NumberFormatter.formatCurrency(apiDto.totalFees || 0, apiDto.currency), totalWithdrawals: apiDto.totalWithdrawals || 0, pendingPayouts: apiDto.pendingPayouts || 0, formattedPendingPayouts: NumberFormatter.formatCurrency(apiDto.pendingPayouts || 0, apiDto.currency), currency: apiDto.currency, transactions, canWithdraw: apiDto.canWithdraw || false, withdrawalBlockReason: apiDto.withdrawalBlockReason, }; } } LeagueWalletViewDataBuilder satisfies ViewDataBuilder;