import type { GetSponsorDashboardResult } from '@core/racing/application/use-cases/GetSponsorDashboardUseCase';
import { SponsorDashboardDTO } from '../dtos/SponsorDashboardDTO';

export class GetSponsorDashboardPresenter {
  private result: SponsorDashboardDTO | null = null;

  reset() {
    this.result = null;
  }

  present(outputPort: GetSponsorDashboardResult | null) {
    if (!outputPort) {
      this.result = null;
      return;
    }

    this.result = {
      sponsorId: outputPort.sponsorId,
      sponsorName: outputPort.sponsorName,
      metrics: outputPort.metrics,
      sponsoredLeagues: outputPort.sponsoredLeagues.map(league => ({
        id: league.leagueId,
        name: league.leagueName,
        tier: league.tier,
        drivers: league.metrics.drivers,
        races: league.metrics.races,
        impressions: league.metrics.impressions,
        status: league.status,
      })),
      investment: {
        activeSponsorships: outputPort.investment.activeSponsorships,
        totalInvestment: outputPort.investment.totalInvestment.amount,
        costPerThousandViews: outputPort.investment.costPerThousandViews,
      },
      sponsorships: {
        leagues: [],
        teams: [],
        drivers: [],
        races: [],
        platform: [],
      },
      recentActivity: [],
      upcomingRenewals: [],
    };
  }

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

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