import { LeagueMemberViewModel } from './LeagueMemberViewModel';
import type { LeagueMemberDTO } from '../types/generated/LeagueMemberDTO';

/**
 * View Model for League Memberships
 *
 * Represents the league's memberships in a UI-ready format.
 */
export class LeagueMembershipsViewModel {
  memberships: LeagueMemberViewModel[];

  constructor(dto: { members?: LeagueMemberDTO[]; memberships?: LeagueMemberDTO[] }, currentUserId: string) {
    const memberships = dto.members ?? dto.memberships ?? [];
    this.memberships = memberships.map((membership) => new LeagueMemberViewModel(membership, currentUserId));
  }

  /** UI-specific: Number of members */
  get memberCount(): number {
    return this.memberships.length;
  }

  /** UI-specific: Whether the league has members */
  get hasMembers(): boolean {
    return this.memberCount > 0;
  }
}
