import { IAllLeaguesWithCapacityPresenter, AllLeaguesWithCapacityResultDTO, AllLeaguesWithCapacityViewModel } from '@core/racing/application/presenters/IAllLeaguesWithCapacityPresenter';

export class AllLeaguesWithCapacityPresenter implements IAllLeaguesWithCapacityPresenter {
  private result: AllLeaguesWithCapacityViewModel | null = null;

  reset() {
    this.result = null;
  }

  present(dto: AllLeaguesWithCapacityResultDTO) {
    const leagues = dto.leagues.map(league => ({
      id: league.id,
      name: league.name,
      description: league.description,
      ownerId: league.ownerId,
      settings: { maxDrivers: league.settings.maxDrivers || 0 },
      createdAt: league.createdAt.toISOString(),
      usedSlots: dto.memberCounts.get(league.id) || 0,
      socialLinks: league.socialLinks,
    }));
    this.result = {
      leagues,
      totalCount: leagues.length,
    };
  }

  getViewModel(): AllLeaguesWithCapacityViewModel | null {
    return this.result;
  }
}