import { Sponsor } from '@core/racing/domain/entities/sponsor/Sponsor';
import { beforeEach, describe, expect, it } from 'vitest';
import { CreateSponsorPresenter } from './CreateSponsorPresenter';

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

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

  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()
      });
      presenter.present(mockSponsor);
      
      const expectedViewModel = {
        sponsor: {
          id: 'sponsor-1',
          name: 'Test Sponsor',
          contactEmail: 'test@example.com',
          createdAt: mockSponsor.createdAt.toDate()
        }
      };
      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()
      });

      presenter.present(mockSponsor);

      const expectedViewModel = {
        sponsor: {
          id: 'sponsor-1',
          name: 'Test Sponsor',
          contactEmail: 'test@example.com',
          createdAt: mockSponsor.createdAt.toDate()
        }
      };
      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()
      });
      presenter.present(mockSponsor);

      const expectedViewModel = {
        sponsor: {
          id: 'sponsor-1',
          name: 'Test Sponsor',
          contactEmail: 'test@example.com',
          createdAt: mockSponsor.createdAt.toDate()
        }
      };
      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()
      });
      presenter.present(mockSponsor);

      const expectedViewModel = {
        sponsor: {
          id: 'sponsor-1',
          name: 'Test Sponsor',
          contactEmail: 'test@example.com',
          createdAt: mockSponsor.createdAt.toDate()
        }
      };
      expect(presenter.viewModel).toEqual(expectedViewModel);
    });
  });
});