import type { GetTotalRacesResult } from '@core/racing/application/use-cases/GetTotalRacesUseCase';
import { GetTotalRacesPresenter } from './GetTotalRacesPresenter';

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

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

  describe('present', () => {
    it('should map result to response model', () => {
      const result: GetTotalRacesResult = { totalRaces: 42 };

      presenter.present(result);

      expect(presenter.responseModel).toEqual({ totalRaces: 42 });
    });

    it('should handle zero races', () => {
      const result: GetTotalRacesResult = { totalRaces: 0 };

      presenter.present(result);

      expect(presenter.responseModel).toEqual({ totalRaces: 0 });
    });

    it('should handle large numbers', () => {
      const result: GetTotalRacesResult = { totalRaces: 999999 };

      presenter.present(result);

      expect(presenter.responseModel).toEqual({ totalRaces: 999999 });
    });
  });

  describe('reset', () => {
    it('should clear the model', () => {
      presenter.present({ totalRaces: 42 });
      expect(presenter.responseModel).toBeDefined();

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

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

  describe('viewModel', () => {
    it('should return same as responseModel', () => {
      const result: GetTotalRacesResult = { totalRaces: 42 };

      presenter.present(result);

      expect(presenter.viewModel).toEqual(presenter.responseModel);
    });
  });
});