import type { ImportRaceResultsApiResult } from '@core/racing/application/use-cases/ImportRaceResultsApiUseCase';
import { ImportRaceResultsSummaryDTO } from '../dtos/ImportRaceResultsSummaryDTO';

export type ImportRaceResultsApiResponseModel = ImportRaceResultsSummaryDTO;

export class ImportRaceResultsApiPresenter {
  private model: ImportRaceResultsApiResponseModel | null = null;

  reset(): void {
    this.model = null;
  }

  present(result: ImportRaceResultsApiResult): void {
    this.model = {
      success: result.success,
      raceId: result.raceId,
      driversProcessed: result.driversProcessed,
      resultsRecorded: result.resultsRecorded,
      errors: result.errors,
    };
  }

  getResponseModel(): ImportRaceResultsApiResponseModel | null {
    return this.model;
  }

  get responseModel(): ImportRaceResultsApiResponseModel {
    if (!this.model) {
      throw new Error('Presenter not presented');
    }

    return this.model;
  }

  get viewModel(): ImportRaceResultsApiResponseModel {
    return this.responseModel;
  }
}