import { describe, it, expect, beforeEach, vi, Mock } from 'vitest';
import { GetRaceRegistrationsUseCase } from './GetRaceRegistrationsUseCase';
import type { IRaceRegistrationRepository } from '@core/racing/domain/repositories/IRaceRegistrationRepository';

describe('GetRaceRegistrationsUseCase', () => {
  let useCase: GetRaceRegistrationsUseCase;
  let registrationRepository: { getRegisteredDrivers: Mock };

  beforeEach(() => {
    registrationRepository = { getRegisteredDrivers: vi.fn() };
    useCase = new GetRaceRegistrationsUseCase(
      registrationRepository as unknown as IRaceRegistrationRepository,
    );
  });

  it('should return registered driver ids', async () => {
    const raceId = 'race-1';
    const registeredDriverIds = ['driver-1', 'driver-2'];

    registrationRepository.getRegisteredDrivers.mockResolvedValue(registeredDriverIds);

    const result = await useCase.execute({ raceId });

    expect(result.isOk()).toBe(true);
    const dto = result.unwrap();
    expect(dto.registeredDriverIds).toEqual(registeredDriverIds);
  });

  it('should return empty array when no registrations', async () => {
    registrationRepository.getRegisteredDrivers.mockResolvedValue([]);

    const result = await useCase.execute({ raceId: 'race-1' });

    expect(result.isOk()).toBe(true);
    const dto = result.unwrap();
    expect(dto.registeredDriverIds).toEqual([]);
  });
});