import { StandingEntryDto, DriverDto } from '../dtos';

export class StandingEntryViewModel implements StandingEntryDto {
  driverId: string;
  driver?: DriverDto;
  position: number;
  points: number;
  wins: number;
  podiums: number;
  races: number;

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

  constructor(dto: StandingEntryDto, leaderPoints: number, nextPoints: number, currentUserId: string, previousPosition?: number) {
    Object.assign(this, dto);
    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();
  }

  /** 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 '-';
    }
  }
}