import { BaseApiClient } from '../base/BaseApiClient';
import type {
  RaceStatsDto,
  RacesPageDataDto,
  RaceDetailDto,
  RaceResultsDetailDto,
  RaceWithSOFDto,
  RegisterForRaceInputDto,
  ImportRaceResultsInputDto,
  ImportRaceResultsSummaryDto,
  WithdrawFromRaceInputDto,
} from '../../dtos';

/**
 * Races API Client
 *
 * Handles all race-related API operations.
 */
export class RacesApiClient extends BaseApiClient {
  /** Get total number of races */
  getTotal(): Promise<RaceStatsDto> {
    return this.get<RaceStatsDto>('/races/total-races');
  }

  /** Get races page data */
  getPageData(): Promise<RacesPageDataDto> {
    return this.get<RacesPageDataDto>('/races/page-data');
  }

  /** Get race detail */
  getDetail(raceId: string, driverId: string): Promise<RaceDetailDto> {
    return this.get<RaceDetailDto>(`/races/${raceId}?driverId=${driverId}`);
  }

  /** Get race results detail */
  getResultsDetail(raceId: string): Promise<RaceResultsDetailDto> {
    return this.get<RaceResultsDetailDto>(`/races/${raceId}/results`);
  }

  /** Get race with strength of field */
  getWithSOF(raceId: string): Promise<RaceWithSOFDto> {
    return this.get<RaceWithSOFDto>(`/races/${raceId}/sof`);
  }

  /** Register for race */
  register(raceId: string, input: RegisterForRaceInputDto): Promise<void> {
    return this.post<void>(`/races/${raceId}/register`, input);
  }

  /** Import race results */
  importResults(raceId: string, input: ImportRaceResultsInputDto): Promise<ImportRaceResultsSummaryDto> {
    return this.post<ImportRaceResultsSummaryDto>(`/races/${raceId}/import-results`, input);
  }

  /** Withdraw from race */
  withdraw(raceId: string, input: WithdrawFromRaceInputDto): Promise<void> {
    return this.post<void>(`/races/${raceId}/withdraw`, input);
  }

  /** Cancel race */
  cancel(raceId: string): Promise<void> {
    return this.post<void>(`/races/${raceId}/cancel`, {});
  }

  /** Complete race */
  complete(raceId: string): Promise<void> {
    return this.post<void>(`/races/${raceId}/complete`, {});
  }
}