import { LeagueWalletViewData, LeagueWalletTransactionViewData } from '@/lib/view-data/leagues/LeagueWalletViewData';
import { LeagueWalletApiDto } from '@/lib/types/tbd/LeagueWalletApiDto';
import { CurrencyDisplay } from '@/lib/display-objects/CurrencyDisplay';
import { DateDisplay } from '@/lib/display-objects/DateDisplay';

export class LeagueWalletViewDataBuilder {
  static build(apiDto: LeagueWalletApiDto): LeagueWalletViewData {
    const transactions: LeagueWalletTransactionViewData[] = apiDto.transactions.map(t => ({
      ...t,
      formattedAmount: CurrencyDisplay.format(t.amount, apiDto.currency),
      amountColor: t.amount >= 0 ? 'green' : 'red',
      formattedDate: DateDisplay.formatShort(t.createdAt),
      statusColor: t.status === 'completed' ? 'green' : t.status === 'pending' ? 'yellow' : 'red',
      typeColor: 'blue',
    }));

    return {
      leagueId: apiDto.leagueId,
      balance: apiDto.balance,
      formattedBalance: CurrencyDisplay.format(apiDto.balance, apiDto.currency),
      totalRevenue: apiDto.balance, // Mock
      formattedTotalRevenue: CurrencyDisplay.format(apiDto.balance, apiDto.currency),
      totalFees: 0, // Mock
      formattedTotalFees: CurrencyDisplay.format(0, apiDto.currency),
      pendingPayouts: 0, // Mock
      formattedPendingPayouts: CurrencyDisplay.format(0, apiDto.currency),
      currency: apiDto.currency,
      transactions,
    };
  }
}
