import { GetLeagueScheduleResult } from '@core/racing/application/use-cases/GetLeagueScheduleUseCase';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import { RaceDTO } from '../../race/dtos/RaceDTO';
import { LeagueScheduleDTO } from '../dtos/LeagueScheduleDTO';

export class LeagueSchedulePresenter implements UseCaseOutputPort<GetLeagueScheduleResult> {
  private result: LeagueScheduleDTO | null = null;

  reset() {
    this.result = null;
  }

  present(result: GetLeagueScheduleResult, leagueName?: string) {
    this.result = {
      seasonId: result.seasonId,
      published: result.published,
      races: result.races.map(race => ({
        id: race.race.id,
        name: `${race.race.track} - ${race.race.car}`,
        date: race.race.scheduledAt.toISOString(),
        ...(leagueName ? { leagueName } : {}),
      })),
    };
  }

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

export class LeagueRacesPresenter implements UseCaseOutputPort<GetLeagueScheduleResult> {
  private result: RaceDTO[] | null = null;

  reset() {
    this.result = null;
  }

  present(result: GetLeagueScheduleResult, leagueName?: string) {
    this.result = result.races.map(race => ({
      id: race.race.id,
      name: `${race.race.track} - ${race.race.car}`,
      date: race.race.scheduledAt.toISOString(),
      ...(leagueName ? { leagueName } : {}),
    }));
  }

  getViewModel(): RaceDTO[] | null {
    return this.result;
  }
}