import type { TeamListItemDTO } from '@/lib/types/generated/TeamListItemDTO';

export class TeamSummaryViewModel {
  id: string;
  name: string;
  tag: string;
  memberCount: number;
  description?: string;
  totalWins: number = 0;
  totalRaces: number = 0;
  performanceLevel: 'beginner' | 'intermediate' | 'advanced' | 'pro' = 'intermediate';
  isRecruiting: boolean = false;
  specialization: 'endurance' | 'sprint' | 'mixed' | undefined;
  region: string | undefined;
  languages: string[] = [];
  leagues: string[] = [];
  logoUrl: string | undefined;
  rating: number | undefined;
  category: string | undefined;

  private maxMembers = 10; // Assuming max members

  constructor(dto: TeamListItemDTO) {
    this.id = dto.id;
    this.name = dto.name;
    this.tag = dto.tag;
    this.memberCount = dto.memberCount;
    this.description = dto.description;
    this.specialization = dto.specialization as 'endurance' | 'sprint' | 'mixed' | undefined;
    this.region = dto.region;
    this.languages = dto.languages ?? [];
    this.leagues = dto.leagues;
    
    // Map stats fields from DTO
    this.totalWins = dto.totalWins ?? 0;
    this.totalRaces = dto.totalRaces ?? 0;
    this.performanceLevel = (dto.performanceLevel as 'beginner' | 'intermediate' | 'advanced' | 'pro') ?? 'intermediate';
    this.logoUrl = dto.logoUrl;
    this.rating = dto.rating;
    this.category = dto.category;
    this.isRecruiting = dto.isRecruiting ?? false;
  }

  /** UI-specific: Whether team is full */
  get isFull(): boolean {
    return this.memberCount >= this.maxMembers;
  }

  /** UI-specific: Tag display */
  get tagDisplay(): string {
    return `[${this.tag}]`;
  }

  /** UI-specific: Member count display */
  get memberCountDisplay(): string {
    return `${this.memberCount}/${this.maxMembers}`;
  }

  /** UI-specific: Status indicator */
  get statusIndicator(): string {
    if (this.isFull) return 'Full';
    return 'Open';
  }

  /** UI-specific: Status color */
  get statusColor(): string {
    return this.isFull ? 'red' : 'green';
  }
}
