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

const createStatusDto = (overrides: Partial<DriverRegistrationStatusDTO> = {}): DriverRegistrationStatusDTO => ({
  isRegistered: true,
  raceId: 'race-1',
  driverId: 'driver-1',
  ...overrides,
});

describe('DriverRegistrationStatusViewModel', () => {
  it('maps basic registration status fields from DTO', () => {
    const dto = createStatusDto({ isRegistered: true });
    const viewModel = new DriverRegistrationStatusViewModel(dto);

    expect(viewModel.isRegistered).toBe(true);
    expect(viewModel.raceId).toBe('race-1');
    expect(viewModel.driverId).toBe('driver-1');
  });

  it('derives UI fields when registered', () => {
    const viewModel = new DriverRegistrationStatusViewModel(createStatusDto({ isRegistered: true }));

    expect(viewModel.statusMessage).toBe('Registered for this race');
    expect(viewModel.statusColor).toBe('green');
    expect(viewModel.statusBadgeVariant).toBe('success');
    expect(viewModel.registrationButtonText).toBe('Withdraw');
    expect(viewModel.canRegister).toBe(false);
  });

  it('derives UI fields when not registered', () => {
    const viewModel = new DriverRegistrationStatusViewModel(createStatusDto({ isRegistered: false }));

    expect(viewModel.statusMessage).toBe('Not registered');
    expect(viewModel.statusColor).toBe('red');
    expect(viewModel.statusBadgeVariant).toBe('warning');
    expect(viewModel.registrationButtonText).toBe('Register');
    expect(viewModel.canRegister).toBe(true);
  });
});
