/** * In-Memory Implementation: ILiveryRepository * * Mock repository for testing and development */ import type { DriverLivery } from '../../domain/entities/DriverLivery'; import type { LiveryTemplate } from '../../domain/entities/LiveryTemplate'; import type { ILiveryRepository } from '../../domain/repositories/ILiveryRepository'; export class InMemoryLiveryRepository implements ILiveryRepository { private driverLiveries: Map = new Map(); private templates: Map = new Map(); // DriverLivery operations async findDriverLiveryById(id: string): Promise { return this.driverLiveries.get(id) ?? null; } async findDriverLiveriesByDriverId(driverId: string): Promise { return Array.from(this.driverLiveries.values()).filter(l => l.driverId === driverId); } async findDriverLiveryByDriverAndCar(driverId: string, carId: string): Promise { for (const livery of this.driverLiveries.values()) { if (livery.driverId === driverId && livery.carId === carId) { return livery; } } return null; } async findDriverLiveriesByGameId(gameId: string): Promise { return Array.from(this.driverLiveries.values()).filter(l => l.gameId === gameId); } async findDriverLiveryByDriverAndGame(driverId: string, gameId: string): Promise { return Array.from(this.driverLiveries.values()).filter( l => l.driverId === driverId && l.gameId === gameId ); } async createDriverLivery(livery: DriverLivery): Promise { if (this.driverLiveries.has(livery.id)) { throw new Error('DriverLivery with this ID already exists'); } this.driverLiveries.set(livery.id, livery); return livery; } async updateDriverLivery(livery: DriverLivery): Promise { if (!this.driverLiveries.has(livery.id)) { throw new Error('DriverLivery not found'); } this.driverLiveries.set(livery.id, livery); return livery; } async deleteDriverLivery(id: string): Promise { this.driverLiveries.delete(id); } // LiveryTemplate operations async findTemplateById(id: string): Promise { return this.templates.get(id) ?? null; } async findTemplatesBySeasonId(seasonId: string): Promise { return Array.from(this.templates.values()).filter(t => t.seasonId === seasonId); } async findTemplateBySeasonAndCar(seasonId: string, carId: string): Promise { for (const template of this.templates.values()) { if (template.seasonId === seasonId && template.carId === carId) { return template; } } return null; } async createTemplate(template: LiveryTemplate): Promise { if (this.templates.has(template.id)) { throw new Error('LiveryTemplate with this ID already exists'); } this.templates.set(template.id, template); return template; } async updateTemplate(template: LiveryTemplate): Promise { if (!this.templates.has(template.id)) { throw new Error('LiveryTemplate not found'); } this.templates.set(template.id, template); return template; } async deleteTemplate(id: string): Promise { this.templates.delete(id); } // Test helpers clearDriverLiveries(): void { this.driverLiveries.clear(); } clearTemplates(): void { this.templates.clear(); } clear(): void { this.driverLiveries.clear(); this.templates.clear(); } }