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

export class InMemoryLeagueScoringConfigRepository implements ILeagueScoringConfigRepository {
  private configs: Map<string, LeagueScoringConfig> = new Map(); // Key: seasonId

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

  async findBySeasonId(seasonId: string): Promise<LeagueScoringConfig | null> {
    this.logger.debug(`[InMemoryLeagueScoringConfigRepository] Finding config for season: ${seasonId}.`);
    const config = this.configs.get(seasonId) ?? null;
    if (config) {
      this.logger.info(`Found config for season: ${seasonId}.`);
    } else {
      this.logger.warn(`No config found for season: ${seasonId}.`);
    }
    return Promise.resolve(config);
  }

  async save(config: LeagueScoringConfig): Promise<LeagueScoringConfig> {
    this.logger.debug(`[InMemoryLeagueScoringConfigRepository] Saving config for season: ${config.seasonId.toString()}.`);
    this.configs.set(config.seasonId.toString(), config);
    this.logger.info(`Config for season ${config.seasonId.toString()} saved successfully.`);
    return Promise.resolve(config);
  }
}
