import { DriverLivery } from '@core/racing/domain/entities/DriverLivery';
import { Result } from '@core/shared/domain/Result';
import { beforeEach, describe, expect, it } from 'vitest';
import { GetDriverLiveriesPresenter } from './GetDriverLiveriesPresenter';

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

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

  describe('present', () => {
    it('should map core result to API response model correctly', () => {
      const mockLiveries: DriverLivery[] = [
        DriverLivery.create({
          id: 'livery1',
          driverId: 'driver1',
          gameId: 'game1',
          carId: 'car1',
          uploadedImageUrl: 'http://example.com/livery1.png',
          createdAt: new Date('2023-01-01'),
        }),
        DriverLivery.create({
          id: 'livery2',
          driverId: 'driver1',
          gameId: 'game1',
          carId: 'car2',
          uploadedImageUrl: 'http://example.com/livery2.png',
          createdAt: new Date('2023-01-02'),
        }),
      ];

      const result = Result.ok(mockLiveries);
      presenter.present(result);

      const response = presenter.getResponseModel();

      expect(response).toEqual({
        liveries: [
          {
            id: 'livery1',
            name: 'Livery for car1',
            imageUrl: 'http://example.com/livery1.png',
            createdAt: '2023-01-01T00:00:00.000Z',
            isActive: true,
          },
          {
            id: 'livery2',
            name: 'Livery for car2',
            imageUrl: 'http://example.com/livery2.png',
            createdAt: '2023-01-02T00:00:00.000Z',
            isActive: false,
          },
        ],
      });
    });

    it('should handle empty liveries array', () => {
      const result = Result.ok([]);
      presenter.present(result);

      const response = presenter.getResponseModel();

      expect(response).toEqual({
        liveries: [],
      });
    });
  });
});