import { describe, it, expect } from 'vitest';
import { SessionViewModel } from './SessionViewModel';
import type { AuthenticatedUserDTO } from '../types/generated/AuthenticatedUserDTO';

describe('SessionViewModel', () => {
  const createDto = (overrides?: Partial<AuthenticatedUserDTO>): AuthenticatedUserDTO => ({
    userId: 'user-1',
    email: 'user@example.com',
    displayName: 'Test User',
    ...overrides,
  });

  it('maps basic user identity fields from the DTO', () => {
    const dto = createDto();
    const viewModel = new SessionViewModel(dto);

    expect(viewModel.userId).toBe('user-1');
    expect(viewModel.email).toBe('user@example.com');
    expect(viewModel.displayName).toBe('Test User');
  });

  it('provides a greeting based on the display name', () => {
    const dto = createDto({ displayName: 'Roo Racer' });
    const viewModel = new SessionViewModel(dto);

    expect(viewModel.greeting).toBe('Hello, Roo Racer!');
  });

  it('derives avatar initials from the display name', () => {
    const dto = createDto({ displayName: 'Roo Racer' });
    const viewModel = new SessionViewModel(dto);

    expect(viewModel.avatarInitials).toBe('RR');
  });

  it('falls back to the email first letter when display name is empty', () => {
    const dto = createDto({ displayName: '' });
    const viewModel = new SessionViewModel(dto);

    expect(viewModel.avatarInitials).toBe('U');
  });

  it('indicates when a driver profile is present via hasDriverProfile', () => {
    const dto = createDto();
    const withoutDriver = new SessionViewModel(dto);

    const withDriver = new SessionViewModel(dto);
    withDriver.driverId = 'driver-1';

    expect(withoutDriver.hasDriverProfile).toBe(false);
    expect(withDriver.hasDriverProfile).toBe(true);
  });

  it('returns the correct authStatusDisplay based on isAuthenticated flag', () => {
    const dto = createDto();
    const authenticated = new SessionViewModel(dto);

    const unauthenticated = new SessionViewModel(dto);
    unauthenticated.isAuthenticated = false;

    expect(authenticated.authStatusDisplay).toBe('Logged In');
    expect(unauthenticated.authStatusDisplay).toBe('Logged Out');
  });
});
