import { describe, it, expect } from 'vitest';
import { RequestAvatarGenerationViewModel } from './RequestAvatarGenerationViewModel';

describe('RequestAvatarGenerationViewModel', () => {
  it('creates instance with successful generation and avatarUrl', () => {
    const dto = {
      success: true,
      avatarUrl: 'https://example.com/generated-avatar.jpg',
    };

    const viewModel = new RequestAvatarGenerationViewModel(dto);

    expect(viewModel.success).toBe(true);
    expect(viewModel.avatarUrl).toBe('https://example.com/generated-avatar.jpg');
    expect(viewModel.error).toBeUndefined();
  });

  it('creates instance with failed generation and error', () => {
    const dto = {
      success: false,
      error: 'Generation failed',
    };

    const viewModel = new RequestAvatarGenerationViewModel(dto);

    expect(viewModel.success).toBe(false);
    expect(viewModel.avatarUrl).toBeUndefined();
    expect(viewModel.error).toBe('Generation failed');
  });

  it('isSuccessful reflects success flag', () => {
    const successVm = new RequestAvatarGenerationViewModel({ success: true });
    const failureVm = new RequestAvatarGenerationViewModel({ success: false });

    expect(successVm.isSuccessful).toBe(true);
    expect(failureVm.isSuccessful).toBe(false);
  });

  it('hasError reflects presence of error message', () => {
    const noErrorVm = new RequestAvatarGenerationViewModel({ success: true });
    const errorVm = new RequestAvatarGenerationViewModel({ success: false, error: 'Something went wrong' });

    expect(noErrorVm.hasError).toBe(false);
    expect(errorVm.hasError).toBe(true);
  });

  it('treats empty error string as no error', () => {
    const viewModel = new RequestAvatarGenerationViewModel({ success: false, error: '' });

    expect(viewModel.hasError).toBe(false);
  });
});
