/** * Infrastructure: InMemorySponsorAccountRepository * * In-memory implementation of ISponsorAccountRepository for development/testing. */ import type { ISponsorAccountRepository } from '../../domain/repositories/ISponsorAccountRepository'; import type { SponsorAccount } from '../../domain/entities/SponsorAccount'; import type { UserId } from '../../domain/value-objects/UserId'; export class InMemorySponsorAccountRepository implements ISponsorAccountRepository { private accounts: Map = new Map(); async save(account: SponsorAccount): Promise { this.accounts.set(account.getId().value, account); } async findById(id: UserId): Promise { return this.accounts.get(id.value) ?? null; } async findBySponsorId(sponsorId: string): Promise { return Array.from(this.accounts.values()).find( a => a.getSponsorId() === sponsorId ) ?? null; } async findByEmail(email: string): Promise { const normalizedEmail = email.toLowerCase().trim(); return Array.from(this.accounts.values()).find( a => a.getEmail().toLowerCase() === normalizedEmail ) ?? null; } async delete(id: UserId): Promise { this.accounts.delete(id.value); } // Helper for testing clear(): void { this.accounts.clear(); } // Helper for seeding demo data seed(accounts: SponsorAccount[]): void { accounts.forEach(a => this.accounts.set(a.getId().value, a)); } }