/** * InMemory implementation of ISponsorshipPricingRepository */ import type { ISponsorshipPricingRepository } from '../../domain/repositories/ISponsorshipPricingRepository'; import { SponsorshipPricing } from '../../domain/value-objects/SponsorshipPricing'; import type { SponsorableEntityType } from '../../domain/entities/SponsorshipRequest'; interface StorageKey { entityType: SponsorableEntityType; entityId: string; } export class InMemorySponsorshipPricingRepository implements ISponsorshipPricingRepository { private pricings: Map = new Map(); private makeKey(entityType: SponsorableEntityType, entityId: string): string { return `${entityType}:${entityId}`; } async findByEntity(entityType: SponsorableEntityType, entityId: string): Promise { const key = this.makeKey(entityType, entityId); const entry = this.pricings.get(key); return entry?.pricing ?? null; } async save(entityType: SponsorableEntityType, entityId: string, pricing: SponsorshipPricing): Promise { const key = this.makeKey(entityType, entityId); this.pricings.set(key, { entityType, entityId, pricing }); } async delete(entityType: SponsorableEntityType, entityId: string): Promise { const key = this.makeKey(entityType, entityId); this.pricings.delete(key); } async exists(entityType: SponsorableEntityType, entityId: string): Promise { const key = this.makeKey(entityType, entityId); return this.pricings.has(key); } async findAcceptingApplications(entityType: SponsorableEntityType): Promise> { return Array.from(this.pricings.values()) .filter(entry => entry.entityType === entityType && entry.pricing.acceptingApplications) .map(entry => ({ entityId: entry.entityId, pricing: entry.pricing })); } /** * Seed initial data */ seed(data: Array<{ entityType: SponsorableEntityType; entityId: string; pricing: SponsorshipPricing }>): void { for (const entry of data) { const key = this.makeKey(entry.entityType, entry.entityId); this.pricings.set(key, entry); } } /** * Clear all data (for testing) */ clear(): void { this.pricings.clear(); } }