import { LeagueScheduleViewData } from '@/lib/view-data/leagues/LeagueScheduleViewData';
import { LeagueScheduleApiDto } from '@/lib/types/tbd/LeagueScheduleApiDto';

export class LeagueScheduleViewDataBuilder {
  static build(apiDto: LeagueScheduleApiDto, currentDriverId?: string, isAdmin: boolean = false): LeagueScheduleViewData {
    const now = new Date();

    return {
      leagueId: apiDto.leagueId,
      races: apiDto.races.map((race) => {
        const scheduledAt = new Date(race.date);
        const isPast = scheduledAt.getTime() < now.getTime();
        const isUpcoming = !isPast;

        return {
          id: race.id,
          name: race.name,
          scheduledAt: race.date,
          track: race.track,
          car: race.car,
          sessionType: race.sessionType,
          isPast,
          isUpcoming,
          status: isPast ? 'completed' : 'scheduled',
          // Registration info (would come from API in real implementation)
          isUserRegistered: false,
          canRegister: isUpcoming,
          // Admin info
          canEdit: isAdmin,
          canReschedule: isAdmin,
        };
      }),
      currentDriverId,
      isAdmin,
    };
  }
}