import type { GetSponsorSponsorshipsResult } from '@core/racing/application/use-cases/GetSponsorSponsorshipsUseCase';
import { Sponsor } from '@core/racing/domain/entities/sponsor/Sponsor';
import { Money } from '@core/racing/domain/value-objects/Money';
import { beforeEach, describe, expect, it } from 'vitest';
import { GetSponsorSponsorshipsPresenter } from './GetSponsorSponsorshipsPresenter';

describe('GetSponsorSponsorshipsPresenter', () => {
  let presenter: GetSponsorSponsorshipsPresenter;

  beforeEach(() => {
    presenter = new GetSponsorSponsorshipsPresenter();
  });

  describe('reset', () => {
    it('should reset the result to null', () => {
      const mockSponsor = Sponsor.create({
        id: 'sponsor-1',
        name: 'Test Sponsor',
        contactEmail: 'test@example.com',
        createdAt: new Date()
      });
      
      const mockResult: GetSponsorSponsorshipsResult = {
        sponsor: mockSponsor,
        sponsorships: [],
        summary: {
          totalSponsorships: 0,
          activeSponsorships: 0,
          totalInvestment: Money.create(0, 'USD'),
          totalPlatformFees: Money.create(0, 'USD'),
        },
      };
      presenter.present(mockResult);
      
      const expectedViewModel = {
        sponsorId: 'sponsor-1',
        sponsorName: 'Test Sponsor',
        sponsorships: [],
        summary: {
          totalSponsorships: 0,
          activeSponsorships: 0,
          totalInvestment: 0,
          totalPlatformFees: 0,
          currency: 'USD',
        },
      };
      expect(presenter.viewModel).toEqual(expectedViewModel);

      presenter.reset();
      expect(() => presenter.viewModel).toThrow('Presenter not presented');
    });
  });

  describe('present', () => {
    it('should store the result', () => {
      const mockSponsor = Sponsor.create({
        id: 'sponsor-1',
        name: 'Test Sponsor',
        contactEmail: 'test@example.com',
        createdAt: new Date()
      });
      
      const mockResult: GetSponsorSponsorshipsResult = {
        sponsor: mockSponsor,
        sponsorships: [],
        summary: {
          totalSponsorships: 0,
          activeSponsorships: 0,
          totalInvestment: Money.create(0, 'USD'),
          totalPlatformFees: Money.create(0, 'USD'),
        },
      };

      presenter.present(mockResult);

      const expectedViewModel = {
        sponsorId: 'sponsor-1',
        sponsorName: 'Test Sponsor',
        sponsorships: [],
        summary: {
          totalSponsorships: 0,
          activeSponsorships: 0,
          totalInvestment: 0,
          totalPlatformFees: 0,
          currency: 'USD',
        },
      };
      expect(presenter.viewModel).toEqual(expectedViewModel);
    });
  });

  describe('getViewModel', () => {
    it('should return null when not presented', () => {
      expect(presenter.getViewModel()).toBeNull();
    });

    it('should return the result when presented', () => {
      const mockSponsor = Sponsor.create({
        id: 'sponsor-1',
        name: 'Test Sponsor',
        contactEmail: 'test@example.com',
        createdAt: new Date()
      });
      
      const mockResult: GetSponsorSponsorshipsResult = {
        sponsor: mockSponsor,
        sponsorships: [],
        summary: {
          totalSponsorships: 0,
          activeSponsorships: 0,
          totalInvestment: Money.create(0, 'USD'),
          totalPlatformFees: Money.create(0, 'USD'),
        },
      };
      presenter.present(mockResult);

      const expectedViewModel = {
        sponsorId: 'sponsor-1',
        sponsorName: 'Test Sponsor',
        sponsorships: [],
        summary: {
          totalSponsorships: 0,
          activeSponsorships: 0,
          totalInvestment: 0,
          totalPlatformFees: 0,
          currency: 'USD',
        },
      };
      expect(presenter.getViewModel()).toEqual(expectedViewModel);
    });
  });

  describe('viewModel', () => {
    it('should throw error when not presented', () => {
      expect(() => presenter.viewModel).toThrow('Presenter not presented');
    });

    it('should return the result when presented', () => {
      const mockSponsor = Sponsor.create({
        id: 'sponsor-1',
        name: 'Test Sponsor',
        contactEmail: 'test@example.com',
        createdAt: new Date()
      });
      
      const mockResult: GetSponsorSponsorshipsResult = {
        sponsor: mockSponsor,
        sponsorships: [],
        summary: {
          totalSponsorships: 0,
          activeSponsorships: 0,
          totalInvestment: Money.create(0, 'USD'),
          totalPlatformFees: Money.create(0, 'USD'),
        },
      };
      presenter.present(mockResult);

      const expectedViewModel = {
        sponsorId: 'sponsor-1',
        sponsorName: 'Test Sponsor',
        sponsorships: [],
        summary: {
          totalSponsorships: 0,
          activeSponsorships: 0,
          totalInvestment: 0,
          totalPlatformFees: 0,
          currency: 'USD',
        },
      };
      expect(presenter.viewModel).toEqual(expectedViewModel);
    });
  });
});