import { IGameRepository } from '@core/racing/domain/repositories/IGameRepository';
import { Game } from '@core/racing/domain/entities/Game';
import { Logger } from '@core/shared/application';

export class InMemoryGameRepository implements IGameRepository {
  private games: Map<string, Game> = new Map();

  constructor(private readonly logger: Logger) {
    this.logger.info('InMemoryGameRepository initialized.');
  }

  async findById(id: string): Promise<Game | null> {
    this.logger.debug(`[InMemoryGameRepository] Finding game by ID: ${id}`);
    const game = this.games.get(id) ?? null;
    if (game) {
      this.logger.info(`Found game by ID: ${id}.`);
    } else {
      this.logger.warn(`Game with ID ${id} not found.`);
    }
    return Promise.resolve(game);
  }

  async findAll(): Promise<Game[]> {
    this.logger.debug('[InMemoryGameRepository] Finding all games.');
    return Promise.resolve(Array.from(this.games.values()));
  }
}
