import type { IAvatarGenerationRepository } from '@gridpilot/media'; import { AvatarGenerationRequest, type AvatarGenerationRequestProps } from '@gridpilot/media'; /** * In-memory implementation of IAvatarGenerationRepository. * * For demo/development purposes. In production, this would use a database. */ export class InMemoryAvatarGenerationRepository implements IAvatarGenerationRepository { private readonly requests = new Map(); async save(request: AvatarGenerationRequest): Promise { this.requests.set(request.id, request.toProps()); } async findById(id: string): Promise { const props = this.requests.get(id); if (!props) { return null; } return AvatarGenerationRequest.reconstitute(props); } async findByUserId(userId: string): Promise { const results: AvatarGenerationRequest[] = []; for (const props of this.requests.values()) { if (props.userId === userId) { results.push(AvatarGenerationRequest.reconstitute(props)); } } return results.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime()); } async findLatestByUserId(userId: string): Promise { const userRequests = await this.findByUserId(userId); return userRequests.length > 0 ? userRequests[0] : null; } async delete(id: string): Promise { this.requests.delete(id); } }