import type { TeamStats, TeamStatsRepository } from '@core/racing/domain/repositories/TeamStatsRepository';
import type { Logger } from '@core/shared/domain/Logger';

export class InMemoryTeamStatsRepository implements TeamStatsRepository {
  private readonly stats = new Map<string, TeamStats>();

  constructor(private readonly logger: Logger) {}

  async getTeamStats(teamId: string): Promise<TeamStats | null> {
    this.logger.debug(`[InMemoryTeamStatsRepository] Getting stats for team: ${teamId}`);
    return this.stats.get(teamId) || null;
  }

  async saveTeamStats(teamId: string, stats: TeamStats): Promise<void> {
    this.logger.debug(`[InMemoryTeamStatsRepository] Saving stats for team: ${teamId}`, stats);
    this.stats.set(teamId, stats);
  }

  async getAllStats(): Promise<Map<string, TeamStats>> {
    this.logger.debug('[InMemoryTeamStatsRepository] Getting all stats');
    return new Map(this.stats);
  }

  async clear(): Promise<void> {
    this.logger.debug('[InMemoryTeamStatsRepository] Clearing all stats');
    this.stats.clear();
  }
}
