/**
 * Application Use Case Interface: DriverStatsUseCase
 * 
 * Use case for computing detailed driver statistics from race results and standings.
 * This is an application layer concern that orchestrates domain data.
 */

import type { ResultRepository } from '../../domain/repositories/ResultRepository';
import type { StandingRepository } from '../../domain/repositories/StandingRepository';
import type { DriverStatsRepository } from '../../domain/repositories/DriverStatsRepository';
import type { Logger } from '@core/shared/domain/Logger';

export interface DriverStats {
  rating: number;
  safetyRating: number;
  sportsmanshipRating: number;
  totalRaces: number;
  wins: number;
  podiums: number;
  dnfs: number;
  avgFinish: number;
  bestFinish: number;
  worstFinish: number;
  consistency: number;
  experienceLevel: string;
  overallRank: number | null;
}

export class DriverStatsUseCase {
  constructor(
    _resultRepository: ResultRepository,
    _standingRepository: StandingRepository,
    private readonly _driverStatsRepository: DriverStatsRepository,
    private readonly _logger: Logger,
  ) {}

  async getDriverStats(driverId: string): Promise<DriverStats | null> {
    this._logger.debug(`Getting stats for driver ${driverId}`);
    return this._driverStatsRepository.getDriverStats(driverId);
  }

  clear(): void {
    this._logger.info('[DriverStatsUseCase] Clearing all stats');
    // No data to clear as this use case generates data on-the-fly
  }
}