import { IAllTeamsPresenter, AllTeamsResultDTO, AllTeamsViewModel, TeamListItemViewModel } from '@core/racing/application/presenters/IAllTeamsPresenter';

export class AllTeamsPresenter implements IAllTeamsPresenter {
  private result: AllTeamsViewModel | null = null;

  reset() {
    this.result = null;
  }

  present(dto: AllTeamsResultDTO) {
    const teams: TeamListItemViewModel[] = dto.teams.map(team => ({
      id: team.id,
      name: team.name,
      tag: team.tag,
      description: team.description,
      memberCount: team.memberCount,
      leagues: team.leagues || [],
    }));

    this.result = {
      teams,
      totalCount: teams.length,
    };
  }

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

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