import type { SponsorSponsorshipsDTO } from '@/lib/types/generated/SponsorSponsorshipsDTO';
import { SponsorshipDetailViewModel } from './SponsorshipDetailViewModel';

/**
 * Sponsor Sponsorships View Model
 *
 * View model for sponsor sponsorships data with UI-specific transformations.
 */
export class SponsorSponsorshipsViewModel {
  sponsorId: string;
  sponsorName: string;

  constructor(dto: SponsorSponsorshipsDTO) {
    this.sponsorId = dto.sponsorId;
    this.sponsorName = dto.sponsorName;
  }

  // Note: The generated DTO doesn't have sponsorships array
  // This will need to be added when the OpenAPI spec is updated
  sponsorships: SponsorshipDetailViewModel[] = [];

  /** UI-specific: Total sponsorships count */
  get totalCount(): number {
    return this.sponsorships.length;
  }

  /** UI-specific: Active sponsorships */
  get activeSponsorships(): SponsorshipDetailViewModel[] {
    return this.sponsorships.filter(s => s.status === 'active');
  }

  /** UI-specific: Active count */
  get activeCount(): number {
    return this.activeSponsorships.length;
  }

  /** UI-specific: Has sponsorships */
  get hasSponsorships(): boolean {
    return this.sponsorships.length > 0;
  }

  /** UI-specific: Total investment */
  get totalInvestment(): number {
    return this.sponsorships.reduce((sum, s) => sum + s.amount, 0);
  }

  /** UI-specific: Formatted total investment */
  get formattedTotalInvestment(): string {
    const firstCurrency = this.sponsorships[0]?.currency || 'USD';
    return `${firstCurrency} ${this.totalInvestment.toLocaleString()}`;
  }
}