import { RaceDetailViewModel } from '../view-models/RaceDetailViewModel';
import type { RaceDetailDto } from '../dtos/RaceDetailDto';
import type { RacesPageDataDto } from '../dtos/RacesPageDataDto';
import type { RacesPageViewModel } from '../view-models/RacesPageViewModel';

/**
 * Race Presenter
 *
 * Stateless presenter that transforms race DTOs into view models.
 * All methods are pure functions with no side effects.
 */
export class RacePresenter {
  presentRaceDetail(dto: RaceDetailDto): RaceDetailViewModel {
    return new RaceDetailViewModel(dto);
  }

  presentRacesPage(dto: RacesPageDataDto): RacesPageViewModel {
    return {
      upcomingRaces: dto.races.filter(r => r.isUpcoming).map(r => this.presentRaceCard(r)),
      completedRaces: dto.races.filter(r => r.status === 'completed').map(r => this.presentRaceCard(r)),
      totalCount: dto.races.length,
    };
  }

  private presentRaceCard(race: any): any {
    return {
      id: race.id,
      title: race.title || race.track,
      scheduledTime: race.scheduledTime || race.scheduledAt,
      status: this.formatStatus(race.status),
    };
  }

  private formatStatus(status: string): string {
    const statusMap: Record<string, string> = {
      scheduled: 'Scheduled',
      running: 'Live',
      completed: 'Finished',
      cancelled: 'Cancelled',
    };
    return statusMap[status] || status;
  }
}