Files
gridpilot.gg/apps/website/lib/view-models/DriverProfileViewModel.ts

141 lines
3.6 KiB
TypeScript

export interface DriverProfileDriverSummaryViewModel {
id: string;
name: string;
country: string;
avatarUrl: string;
iracingId: string | null;
joinedAt: string;
rating: number | null;
globalRank: number | null;
consistency: number | null;
bio: string | null;
totalDrivers: number | null;
}
export interface DriverProfileStatsViewModel {
totalRaces: number;
wins: number;
podiums: number;
dnfs: number;
avgFinish: number | null;
bestFinish: number | null;
worstFinish: number | null;
finishRate: number | null;
winRate: number | null;
podiumRate: number | null;
percentile: number | null;
rating: number | null;
consistency: number | null;
overallRank: number | null;
}
export interface DriverProfileFinishDistributionViewModel {
totalRaces: number;
wins: number;
podiums: number;
topTen: number;
dnfs: number;
other: number;
}
export interface DriverProfileTeamMembershipViewModel {
teamId: string;
teamName: string;
teamTag: string | null;
role: string;
joinedAt: string;
isCurrent: boolean;
}
export interface DriverProfileSocialFriendSummaryViewModel {
id: string;
name: string;
country: string;
avatarUrl: string;
}
export interface DriverProfileSocialSummaryViewModel {
friendsCount: number;
friends: DriverProfileSocialFriendSummaryViewModel[];
}
export type DriverProfileSocialPlatform = 'twitter' | 'youtube' | 'twitch' | 'discord';
export type DriverProfileAchievementRarity = 'common' | 'rare' | 'epic' | 'legendary';
export interface DriverProfileAchievementViewModel {
id: string;
title: string;
description: string;
icon: 'trophy' | 'medal' | 'star' | 'crown' | 'target' | 'zap';
rarity: DriverProfileAchievementRarity;
earnedAt: string;
}
export interface DriverProfileSocialHandleViewModel {
platform: DriverProfileSocialPlatform;
handle: string;
url: string;
}
export interface DriverProfileExtendedProfileViewModel {
socialHandles: DriverProfileSocialHandleViewModel[];
achievements: DriverProfileAchievementViewModel[];
racingStyle: string;
favoriteTrack: string;
favoriteCar: string;
timezone: string;
availableHours: string;
lookingForTeam: boolean;
openToRequests: boolean;
}
export interface DriverProfileViewModel {
currentDriver: DriverProfileDriverSummaryViewModel | null;
stats: DriverProfileStatsViewModel | null;
finishDistribution: DriverProfileFinishDistributionViewModel | null;
teamMemberships: DriverProfileTeamMembershipViewModel[];
socialSummary: DriverProfileSocialSummaryViewModel;
extendedProfile: DriverProfileExtendedProfileViewModel | null;
}
/**
* Driver Profile View Model
*
* Represents a fully prepared UI state for driver profile display.
* Transforms API DTOs into UI-ready data structures.
*/
export class DriverProfileViewModel {
constructor(private readonly dto: DriverProfileViewModel) {}
get currentDriver(): DriverProfileDriverSummaryViewModel | null {
return this.dto.currentDriver;
}
get stats(): DriverProfileStatsViewModel | null {
return this.dto.stats;
}
get finishDistribution(): DriverProfileFinishDistributionViewModel | null {
return this.dto.finishDistribution;
}
get teamMemberships(): DriverProfileTeamMembershipViewModel[] {
return this.dto.teamMemberships;
}
get socialSummary(): DriverProfileSocialSummaryViewModel {
return this.dto.socialSummary;
}
get extendedProfile(): DriverProfileExtendedProfileViewModel | null {
return this.dto.extendedProfile;
}
/**
* Get the raw DTO for serialization or further processing
*/
toDTO(): DriverProfileViewModel {
return this.dto;
}
}