import { GetMediaPresenter } from './GetMediaPresenter';

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

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

  describe('transform', () => {
    it('should map result to response model', () => {
      const result = {
        media: {
          id: 'media-123',
          filename: 'avatar.png',
          originalName: 'my-avatar.png',
          mimeType: 'image/png',
          size: 12345,
          url: 'https://example.com/avatar.png',
          type: 'image',
          uploadedBy: 'user-456',
          uploadedAt: new Date('2024-01-01'),
        },
      };

      const response = presenter.transform(result);

      expect(response).toEqual({
        id: 'media-123',
        url: 'https://example.com/avatar.png',
        type: 'image',
        uploadedAt: new Date('2024-01-01'),
        size: 12345,
      });
    });

    it('should handle metadata', () => {
      const result = {
        media: {
          id: 'media-123',
          filename: 'avatar.png',
          originalName: 'my-avatar.png',
          mimeType: 'image/png',
          size: 12345,
          url: 'https://example.com/avatar.png',
          type: 'image',
          uploadedBy: 'user-456',
          uploadedAt: new Date('2024-01-01'),
          metadata: { category: 'profile', width: 100, height: 100 },
        },
      };

      const response = presenter.transform(result);

      expect(response).toEqual({
        id: 'media-123',
        url: 'https://example.com/avatar.png',
        type: 'image',
        uploadedAt: new Date('2024-01-01'),
        size: 12345,
        category: 'profile',
      });
    });

    it('should handle result without metadata', () => {
      const result = {
        media: {
          id: 'media-123',
          filename: 'avatar.png',
          originalName: 'my-avatar.png',
          mimeType: 'image/png',
          size: 12345,
          url: 'https://example.com/avatar.png',
          type: 'image',
          uploadedBy: 'user-456',
          uploadedAt: new Date('2024-01-01'),
        },
      };

      const response = presenter.transform(result);

      expect(response?.category).toBeUndefined();
    });
  });

  describe('reset', () => {
    it('should clear the model', () => {
      presenter.transform({
        media: {
          id: 'media-123',
          filename: 'avatar.png',
          originalName: 'my-avatar.png',
          mimeType: 'image/png',
          size: 12345,
          url: 'https://example.com/avatar.png',
          type: 'image',
          uploadedBy: 'user-456',
          uploadedAt: new Date('2024-01-01'),
        },
      });
      expect(presenter.getResponseModel()).not.toBeNull();

      presenter.reset();
      expect(presenter.getResponseModel()).toBeNull();
    });
  });

  describe('responseModel', () => {
    it('should return null when model is null', () => {
      expect(presenter.responseModel).toBeNull();
    });

    it('should return model after transform()', () => {
      presenter.transform({
        media: {
          id: 'media-123',
          filename: 'avatar.png',
          originalName: 'my-avatar.png',
          mimeType: 'image/png',
          size: 12345,
          url: 'https://example.com/avatar.png',
          type: 'image',
          uploadedBy: 'user-456',
          uploadedAt: new Date('2024-01-01'),
        },
      });
      expect(presenter.responseModel).toEqual({
        id: 'media-123',
        url: 'https://example.com/avatar.png',
        type: 'image',
        uploadedAt: new Date('2024-01-01'),
        size: 12345,
      });
    });
  });

  describe('getResponseModel', () => {
    it('should return null before transform()', () => {
      expect(presenter.getResponseModel()).toBeNull();
    });

    it('should return model after transform()', () => {
      presenter.transform({
        media: {
          id: 'media-123',
          filename: 'avatar.png',
          originalName: 'my-avatar.png',
          mimeType: 'image/png',
          size: 12345,
          url: 'https://example.com/avatar.png',
          type: 'image',
          uploadedBy: 'user-456',
          uploadedAt: new Date('2024-01-01'),
        },
      });
      expect(presenter.getResponseModel()).toEqual({
        id: 'media-123',
        url: 'https://example.com/avatar.png',
        type: 'image',
        uploadedAt: new Date('2024-01-01'),
        size: 12345,
      });
    });
  });
});