import type { GetLeagueOwnerSummaryResult } from '@core/racing/application/use-cases/GetLeagueOwnerSummaryUseCase';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import { LeagueOwnerSummaryDTO } from '../dtos/LeagueOwnerSummaryDTO';

export class GetLeagueOwnerSummaryPresenter implements UseCaseOutputPort<GetLeagueOwnerSummaryResult> {
  private result: LeagueOwnerSummaryDTO | null = null;

  reset() {
    this.result = null;
  }

  present(output: GetLeagueOwnerSummaryResult) {
    this.result = {
      driver: {
        id: output.owner.id,
        iracingId: output.owner.iracingId.toString(),
        name: output.owner.name.toString(),
        country: output.owner.country.toString(),
        joinedAt: output.owner.joinedAt.toDate().toISOString(),
        ...(output.owner.bio ? { bio: output.owner.bio.toString() } : {}),
      },
      rating: output.rating,
      rank: output.rank,
    };
  }

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