import type { Sponsor } from '@core/racing/domain/entities/sponsor/Sponsor';
import type { CreateSponsorOutputDTO } from '../dtos/CreateSponsorOutputDTO';
import { SponsorDTO } from '../dtos/SponsorDTO';

export class CreateSponsorPresenter {
  private result: CreateSponsorOutputDTO | null = null;

  reset() {
    this.result = null;
  }

  present(sponsor: Sponsor) {
    const sponsorData = new SponsorDTO();
    sponsorData.id = sponsor.id.toString();
    sponsorData.name = sponsor.name.toString();
    sponsorData.contactEmail = sponsor.contactEmail.toString();
    sponsorData.createdAt = sponsor.createdAt.toDate();

    if (sponsor.logoUrl) {
      sponsorData.logoUrl = sponsor.logoUrl.toString();
    }

    if (sponsor.websiteUrl) {
      sponsorData.websiteUrl = sponsor.websiteUrl.toString();
    }

    this.result = {
      sponsor: sponsorData,
    };
  }

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

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