import { ITeamsLeaderboardPresenter, TeamsLeaderboardResultDTO, TeamsLeaderboardViewModel } from '@core/racing/application/presenters/ITeamsLeaderboardPresenter';

export class TeamsLeaderboardPresenter implements ITeamsLeaderboardPresenter {
  private result: TeamsLeaderboardViewModel | null = null;

  reset() {
    this.result = null;
  }

  present(dto: TeamsLeaderboardResultDTO) {
    this.result = {
      teams: dto.teams as any, // Cast to match the view model
      recruitingCount: dto.recruitingCount,
      groupsBySkillLevel: {
        beginner: [],
        intermediate: [],
        advanced: [],
        pro: [],
      },
      topTeams: dto.teams.slice(0, 10) as any,
    };
  }

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

  get viewModel(): TeamsLeaderboardViewModel {
    if (!this.result) throw new Error('Presenter not presented');
    return this.result;
  }
}