/** * Infrastructure Adapter: InMemoryDriverStatsRepository * * In-memory implementation of IDriverStatsRepository. * Stores computed driver statistics for caching and frontend queries. */ import type { DriverStats } from '@core/racing/application/use-cases/DriverStatsUseCase'; import type { DriverStatsRepository } from '@core/racing/domain/repositories/DriverStatsRepository'; import type { Logger } from '@core/shared/domain/Logger'; export class InMemoryDriverStatsRepository implements DriverStatsRepository { private stats = new Map(); constructor(private readonly logger: Logger) { this.logger.info('[InMemoryDriverStatsRepository] Initialized.'); } async getDriverStats(driverId: string): Promise { this.logger.debug(`[InMemoryDriverStatsRepository] Getting stats for driver: ${driverId}`); return this.stats.get(driverId) ?? null; } getDriverStatsSync(driverId: string): DriverStats | null { this.logger.debug(`[InMemoryDriverStatsRepository] Getting stats (sync) for driver: ${driverId}`); return this.stats.get(driverId) ?? null; } async saveDriverStats(driverId: string, stats: DriverStats): Promise { this.logger.debug(`[InMemoryDriverStatsRepository] Saving stats for driver: ${driverId}`); this.stats.set(driverId, stats); } async getAllStats(): Promise> { this.logger.debug('[InMemoryDriverStatsRepository] Getting all stats'); return new Map(this.stats); } async clear(): Promise { this.logger.info('[InMemoryDriverStatsRepository] Clearing all stats'); this.stats.clear(); } }