/** * In-Memory Implementation: InMemoryWalletRepository */ import type { Transaction, Wallet } from '@core/payments/domain/entities/Wallet'; import type { WalletRepository, TransactionRepository } from '@core/payments/domain/repositories/WalletRepository'; import type { Logger } from '@core/shared/domain/Logger'; import type { LeagueWalletRepository } from '@core/racing/domain/repositories/LeagueWalletRepository'; const wallets: Map = new Map(); const transactions: Map = new Map(); export class InMemoryWalletRepository implements WalletRepository, LeagueWalletRepository { constructor(private readonly logger: Logger) {} async findById(id: string): Promise { this.logger.debug('[InMemoryWalletRepository] findById', { id }); return wallets.get(id) || null; } async findByLeagueId(leagueId: string): Promise { this.logger.debug('[InMemoryWalletRepository] findByLeagueId', { leagueId }); return Array.from(wallets.values()).find(w => w.leagueId.toString() === leagueId) || null; } async create(wallet: any): Promise { this.logger.debug('[InMemoryWalletRepository] create', { wallet }); wallets.set(wallet.id.toString(), wallet); return wallet; } async update(wallet: any): Promise { this.logger.debug('[InMemoryWalletRepository] update', { wallet }); wallets.set(wallet.id.toString(), wallet); return wallet; } async delete(id: string): Promise { wallets.delete(id); } async exists(id: string): Promise { return wallets.has(id); } clear(): void { wallets.clear(); } } export class InMemoryTransactionRepository implements TransactionRepository { constructor(private readonly logger: Logger) {} async findById(id: string): Promise { this.logger.debug('[InMemoryTransactionRepository] findById', { id }); return transactions.get(id) || null; } async findByWalletId(walletId: string): Promise { this.logger.debug('[InMemoryTransactionRepository] findByWalletId', { walletId }); return Array.from(transactions.values()).filter(t => t.walletId.toString() === walletId); } async create(transaction: any): Promise { this.logger.debug('[InMemoryTransactionRepository] create', { transaction }); transactions.set(transaction.id.toString(), transaction); return transaction; } async update(transaction: any): Promise { transactions.set(transaction.id.toString(), transaction); return transaction; } async delete(id: string): Promise { transactions.delete(id); } async exists(id: string): Promise { return transactions.has(id); } findByType(type: any): Promise { return Promise.resolve(Array.from(transactions.values()).filter(t => t.type === type)); } clear(): void { transactions.clear(); } }