import type { Presenter } from '../../../shared/presentation/Presenter';
import type { GetLeagueSeasonsResult } from '@core/racing/application/use-cases/GetLeagueSeasonsUseCase';
import { LeagueSeasonSummaryDTO } from '../dtos/LeagueSeasonSummaryDTO';

export class GetLeagueSeasonsPresenter implements Presenter<GetLeagueSeasonsResult, LeagueSeasonSummaryDTO[]> {
  private result: LeagueSeasonSummaryDTO[] | null = null;

  reset() {
    this.result = null;
  }

  present(input: GetLeagueSeasonsResult) {
    this.result = input.seasons.map((seasonSummary) => {
      const dto = new LeagueSeasonSummaryDTO();
      dto.seasonId = seasonSummary.season.id.toString();
      dto.name = seasonSummary.season.name.toString();
      dto.status = seasonSummary.season.status.toString();

      if (seasonSummary.season.startDate) dto.startDate = seasonSummary.season.startDate;
      if (seasonSummary.season.endDate) dto.endDate = seasonSummary.season.endDate;

      dto.isPrimary = seasonSummary.isPrimary;
      dto.isParallelActive = seasonSummary.isParallelActive;

      return dto;
    });
  }

  getResponseModel(): LeagueSeasonSummaryDTO[] | null {
    return this.result;
  }
}