import { RequestAvatarGenerationPresenter } from './RequestAvatarGenerationPresenter';

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

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

  describe('transform', () => {
    it('should map completed result to response model', () => {
      const result = {
        requestId: 'req-123',
        status: 'completed' as const,
        avatarUrls: ['https://example.com/avatar1.png', 'https://example.com/avatar2.png'],
      };

      const response = presenter.transform(result);

      expect(response).toEqual({
        success: true,
        requestId: 'req-123',
        avatarUrls: ['https://example.com/avatar1.png', 'https://example.com/avatar2.png'],
      });
    });

    it('should handle empty avatarUrls', () => {
      const result = {
        requestId: 'req-123',
        status: 'completed' as const,
        avatarUrls: [],
      };

      const response = presenter.transform(result);

      expect(response).toEqual({
        success: true,
        requestId: 'req-123',
        avatarUrls: [],
      });
    });

    it('should handle undefined avatarUrls', () => {
      const result = {
        requestId: 'req-123',
        status: 'completed' as const,
      };

      const response = presenter.transform(result);

      expect(response).toEqual({
        success: true,
        requestId: 'req-123',
        avatarUrls: [],
      });
    });

    it('should handle non-completed status', () => {
      const result = {
        requestId: 'req-123',
        status: 'generating' as const,
        avatarUrls: [],
      };

      const response = presenter.transform(result);

      expect(response).toEqual({
        success: false,
        requestId: 'req-123',
        avatarUrls: [],
      });
    });
  });

  describe('reset', () => {
    it('should clear the model', () => {
      presenter.transform({
        requestId: 'req-123',
        status: 'completed' as const,
        avatarUrls: ['https://example.com/avatar1.png'],
      });
      expect(presenter.getResponseModel()).not.toBeNull();

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

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

    it('should return model after transform()', () => {
      presenter.transform({
        requestId: 'req-123',
        status: 'completed' as const,
        avatarUrls: ['https://example.com/avatar1.png'],
      });
      expect(presenter.responseModel).toEqual({
        success: true,
        requestId: 'req-123',
        avatarUrls: ['https://example.com/avatar1.png'],
      });
    });
  });

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

    it('should return model after transform()', () => {
      presenter.transform({
        requestId: 'req-123',
        status: 'completed' as const,
        avatarUrls: ['https://example.com/avatar1.png'],
      });
      expect(presenter.getResponseModel()).toEqual({
        success: true,
        requestId: 'req-123',
        avatarUrls: ['https://example.com/avatar1.png'],
      });
    });
  });
});