import type { IRaceRegistrationRepository } from '@core/racing/domain/repositories/IRaceRegistrationRepository';
import type { GetRaceRegistrationsQueryParamsDTO } from '../dto/RaceRegistrationQueryDTO';
import type { RaceRegistrationsResultDTO } from '../presenters/IRaceRegistrationsPresenter';
import type { AsyncUseCase } from '@core/shared/application/AsyncUseCase';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';

/**
 * Use Case: GetRaceRegistrationsUseCase
 *
 * Returns registered driver IDs for a race.
 * Orchestrates domain logic and delegates presentation to the presenter.
 */
export class GetRaceRegistrationsUseCase implements AsyncUseCase<GetRaceRegistrationsQueryParamsDTO, RaceRegistrationsResultDTO, 'NO_ERROR'> {
  constructor(
    private readonly registrationRepository: IRaceRegistrationRepository,
  ) {}

  async execute(params: GetRaceRegistrationsQueryParamsDTO): Promise<Result<RaceRegistrationsResultDTO, ApplicationErrorCode<'NO_ERROR'>>> {
    const { raceId } = params;
    const registeredDriverIds = await this.registrationRepository.getRegisteredDrivers(raceId);

    const dto: RaceRegistrationsResultDTO = {
      registeredDriverIds,
    };

    return Result.ok(dto);
  }
}