import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder'; import { NumberFormatter } from '@/lib/formatters/NumberFormatter'; import { RatingFormatter } from '@/lib/formatters/RatingFormatter'; import type { DriversLeaderboardDTO } from '@/lib/types/generated/DriversLeaderboardDTO'; import type { DriversViewData } from '@/lib/view-data/DriversViewData'; export class DriversViewDataBuilder { public static build(apiDto: DriversLeaderboardDTO): DriversViewData { return { drivers: apiDto.drivers.map(driver => ({ id: driver.id, name: driver.name, rating: driver.rating, ratingLabel: RatingFormatter.format(driver.rating), skillLevel: driver.skillLevel, category: driver.category ?? undefined, nationality: driver.nationality, racesCompleted: driver.racesCompleted, wins: driver.wins, podiums: driver.podiums, isActive: driver.isActive, rank: driver.rank, avatarUrl: driver.avatarUrl ?? undefined, })), totalRaces: apiDto.totalRaces, totalRacesLabel: NumberFormatter.format(apiDto.totalRaces), totalWins: apiDto.totalWins, totalWinsLabel: NumberFormatter.format(apiDto.totalWins), activeCount: apiDto.activeCount, activeCountLabel: NumberFormatter.format(apiDto.activeCount), totalDriversLabel: NumberFormatter.format(apiDto.drivers.length), }; } } DriversViewDataBuilder satisfies ViewDataBuilder;