import type { DriverLeaderboardItemDTO } from '@/lib/types/generated/DriverLeaderboardItemDTO';
import type { GetTeamsLeaderboardOutputDTO } from '@/lib/types/generated/GetTeamsLeaderboardOutputDTO';
import type { LeaderboardsViewData } from '@/lib/view-data/LeaderboardsViewData';

export class LeaderboardsViewDataBuilder {
  static build(
    apiDto: { drivers: { drivers: DriverLeaderboardItemDTO[] }; teams: GetTeamsLeaderboardOutputDTO }
  ): LeaderboardsViewData {
    return {
      drivers: apiDto.drivers.drivers.map(driver => ({
        id: driver.id,
        name: driver.name,
        rating: driver.rating,
        skillLevel: driver.skillLevel,
        nationality: driver.nationality,
        wins: driver.wins,
        podiums: driver.podiums,
        racesCompleted: driver.racesCompleted,
        rank: driver.rank,
        avatarUrl: driver.avatarUrl || '',
        position: driver.rank,
      })),
      teams: apiDto.teams.topTeams.map((team, index) => ({
        id: team.id,
        name: team.name,
        tag: team.tag,
        memberCount: team.memberCount,
        category: undefined,
        totalWins: team.totalWins || 0,
        totalRaces: team.totalRaces || 0,
        logoUrl: team.logoUrl || '',
        position: index + 1,
        isRecruiting: team.isRecruiting,
        performanceLevel: team.performanceLevel || 'N/A',
        rating: team.rating || 0,
      })),
    };
  }
}
