import { LeagueStandingDTO } from '../types/generated/LeagueStandingDTO';

export class StandingEntryViewModel {
  driverId: string;
  position: number;
  points: number;
  wins: number;
  podiums: number;
  races: number;

  private leaderPoints: number;
  private nextPoints: number;
  private currentUserId: string;
  private previousPosition?: number;

  constructor(dto: LeagueStandingDTO, leaderPoints: number, nextPoints: number, currentUserId: string, previousPosition?: number) {
    this.driverId = dto.driverId;
    this.position = dto.position;
    this.points = dto.points;
    this.wins = dto.wins ?? 0;
    this.podiums = dto.podiums ?? 0;
    this.races = dto.races ?? 0;
    this.leaderPoints = leaderPoints;
    this.nextPoints = nextPoints;
    this.currentUserId = currentUserId;
    this.previousPosition = previousPosition;
  }

  /** UI-specific: Badge for position display */
  get positionBadge(): string {
    return this.position.toString();
  }

  // Note: The generated DTO is incomplete
  // These fields will need to be added when the OpenAPI spec is updated
  driver?: any;

  /** UI-specific: Points difference to leader */
  get pointsGapToLeader(): number {
    return this.points - this.leaderPoints;
  }

  /** UI-specific: Points difference to next position */
  get pointsGapToNext(): number {
    return this.points - this.nextPoints;
  }

  /** UI-specific: Whether this entry is the current user */
  get isCurrentUser(): boolean {
    return this.driverId === this.currentUserId;
  }

  /** UI-specific: Trend compared to previous */
  get trend(): 'up' | 'down' | 'same' {
    if (!this.previousPosition) return 'same';
    if (this.position < this.previousPosition) return 'up';
    if (this.position > this.previousPosition) return 'down';
    return 'same';
  }

  /** UI-specific: Arrow for trend */
  get trendArrow(): string {
    switch (this.trend) {
      case 'up': return '↑';
      case 'down': return '↓';
      default: return '-';
    }
  }
}