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

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

  reset() {
    this.result = null;
  }

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

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