import { RacesApiClient } from '../../api/races/RacesApiClient';
import { RaceDetailPresenter } from '../../presenters/RaceDetailPresenter';
import type { RaceDetailViewModel } from '../../view-models/RaceDetailViewModel';
import type { RacesPageDataDto, RaceStatsDto } from '../../dtos';

/**
 * Race Service
 *
 * Orchestrates race operations by coordinating API calls and presentation logic.
 * All dependencies are injected via constructor.
 */
export class RaceService {
  constructor(
    private readonly apiClient: RacesApiClient,
    private readonly raceDetailPresenter: RaceDetailPresenter
  ) {}

  /**
   * Get race detail with presentation transformation
   */
  async getRaceDetail(
    raceId: string,
    driverId: string
  ): Promise<RaceDetailViewModel> {
    const dto = await this.apiClient.getDetail(raceId, driverId);
    return this.raceDetailPresenter.present(dto);
  }

  /**
   * Get races page data
   * TODO: Add presenter transformation when presenter is available
   */
  async getRacesPageData(): Promise<RacesPageDataDto> {
    return this.apiClient.getPageData();
  }

  /**
   * Get total races statistics
   * TODO: Add presenter transformation when presenter is available
   */
  async getRacesTotal(): Promise<RaceStatsDto> {
    return this.apiClient.getTotal();
  }
}