import { Inject, Injectable } from '@nestjs/common'; // DTOs import { GetRaceDetailParamsDTO } from './dtos/GetRaceDetailParamsDTO'; import { ImportRaceResultsDTO } from './dtos/ImportRaceResultsDTO'; import { RaceActionParamsDTO } from './dtos/RaceActionParamsDTO'; import { RegisterForRaceParamsDTO } from './dtos/RegisterForRaceParamsDTO'; import { WithdrawFromRaceParamsDTO } from './dtos/WithdrawFromRaceParamsDTO'; // Core imports import type { Logger } from '@core/shared/application/Logger'; // Use cases import { CancelRaceUseCase } from '@core/racing/application/use-cases/CancelRaceUseCase'; import { CompleteRaceUseCase } from '@core/racing/application/use-cases/CompleteRaceUseCase'; import { FileProtestUseCase } from '@core/racing/application/use-cases/FileProtestUseCase'; import { GetAllRacesPageDataUseCase } from '@core/racing/application/use-cases/GetAllRacesPageDataUseCase'; import { GetAllRacesUseCase } from '@core/racing/application/use-cases/GetAllRacesUseCase'; import { GetRaceDetailUseCase } from '@core/racing/application/use-cases/GetRaceDetailUseCase'; import { GetRacePenaltiesUseCase } from '@core/racing/application/use-cases/GetRacePenaltiesUseCase'; import { GetRaceProtestsUseCase } from '@core/racing/application/use-cases/GetRaceProtestsUseCase'; import { GetRaceResultsDetailUseCase } from '@core/racing/application/use-cases/GetRaceResultsDetailUseCase'; import { GetRacesPageDataUseCase } from '@core/racing/application/use-cases/GetRacesPageDataUseCase'; import { GetRaceWithSOFUseCase } from '@core/racing/application/use-cases/GetRaceWithSOFUseCase'; import { GetTotalRacesUseCase } from '@core/racing/application/use-cases/GetTotalRacesUseCase'; import { ImportRaceResultsApiUseCase } from '@core/racing/application/use-cases/ImportRaceResultsApiUseCase'; import { QuickPenaltyUseCase } from '@core/racing/application/use-cases/QuickPenaltyUseCase'; import { RegisterForRaceUseCase } from '@core/racing/application/use-cases/RegisterForRaceUseCase'; import { ReopenRaceUseCase } from '@core/racing/application/use-cases/ReopenRaceUseCase'; import { RequestProtestDefenseUseCase } from '@core/racing/application/use-cases/RequestProtestDefenseUseCase'; import { ReviewProtestUseCase } from '@core/racing/application/use-cases/ReviewProtestUseCase'; import { WithdrawFromRaceUseCase } from '@core/racing/application/use-cases/WithdrawFromRaceUseCase'; // Presenters import { AllRacesPageDataPresenter } from './presenters/AllRacesPageDataPresenter'; import { CommandResultPresenter } from './presenters/CommandResultPresenter'; import { GetAllRacesPresenter } from './presenters/GetAllRacesPresenter'; import { GetTotalRacesPresenter } from './presenters/GetTotalRacesPresenter'; import { ImportRaceResultsApiPresenter } from './presenters/ImportRaceResultsApiPresenter'; import { RaceDetailPresenter } from './presenters/RaceDetailPresenter'; import { RacePenaltiesPresenter } from './presenters/RacePenaltiesPresenter'; import { RaceProtestsPresenter } from './presenters/RaceProtestsPresenter'; import { RaceResultsDetailPresenter } from './presenters/RaceResultsDetailPresenter'; import { RacesPageDataPresenter } from './presenters/RacesPageDataPresenter'; import { RaceWithSOFPresenter } from './presenters/RaceWithSOFPresenter'; // Command DTOs import { ApplyPenaltyCommandDTO } from './dtos/ApplyPenaltyCommandDTO'; import { FileProtestCommandDTO } from './dtos/FileProtestCommandDTO'; import { QuickPenaltyCommandDTO } from './dtos/QuickPenaltyCommandDTO'; import { RequestProtestDefenseCommandDTO } from './dtos/RequestProtestDefenseCommandDTO'; import { ReviewProtestCommandDTO } from './dtos/ReviewProtestCommandDTO'; // Tokens import { ApplyPenaltyUseCase } from '@core/racing/application/use-cases/ApplyPenaltyUseCase'; import { ALL_RACES_PAGE_DATA_PRESENTER_TOKEN, COMMAND_RESULT_PRESENTER_TOKEN, GET_ALL_RACES_PRESENTER_TOKEN, GET_TOTAL_RACES_PRESENTER_TOKEN, IMPORT_RACE_RESULTS_API_PRESENTER_TOKEN, LOGGER_TOKEN, RACE_DETAIL_PRESENTER_TOKEN, RACE_PENALTIES_PRESENTER_TOKEN, RACE_PROTESTS_PRESENTER_TOKEN, RACE_RESULTS_DETAIL_PRESENTER_TOKEN, RACE_WITH_SOF_PRESENTER_TOKEN, RACES_PAGE_DATA_PRESENTER_TOKEN } from './RaceProviders'; @Injectable() export class RaceService { constructor( private readonly getAllRacesUseCase: GetAllRacesUseCase, private readonly getTotalRacesUseCase: GetTotalRacesUseCase, private readonly importRaceResultsApiUseCase: ImportRaceResultsApiUseCase, private readonly getRaceDetailUseCase: GetRaceDetailUseCase, private readonly getRacesPageDataUseCase: GetRacesPageDataUseCase, private readonly getAllRacesPageDataUseCase: GetAllRacesPageDataUseCase, private readonly getRaceResultsDetailUseCase: GetRaceResultsDetailUseCase, private readonly getRaceWithSOFUseCase: GetRaceWithSOFUseCase, private readonly getRaceProtestsUseCase: GetRaceProtestsUseCase, private readonly getRacePenaltiesUseCase: GetRacePenaltiesUseCase, private readonly registerForRaceUseCase: RegisterForRaceUseCase, private readonly withdrawFromRaceUseCase: WithdrawFromRaceUseCase, private readonly cancelRaceUseCase: CancelRaceUseCase, private readonly completeRaceUseCase: CompleteRaceUseCase, private readonly fileProtestUseCase: FileProtestUseCase, private readonly quickPenaltyUseCase: QuickPenaltyUseCase, private readonly applyPenaltyUseCase: ApplyPenaltyUseCase, private readonly requestProtestDefenseUseCase: RequestProtestDefenseUseCase, private readonly reviewProtestUseCase: ReviewProtestUseCase, private readonly reopenRaceUseCase: ReopenRaceUseCase, @Inject(LOGGER_TOKEN) private readonly logger: Logger, // Injected presenters @Inject(GET_ALL_RACES_PRESENTER_TOKEN) private readonly getAllRacesPresenter: GetAllRacesPresenter, @Inject(GET_TOTAL_RACES_PRESENTER_TOKEN) private readonly getTotalRacesPresenter: GetTotalRacesPresenter, @Inject(IMPORT_RACE_RESULTS_API_PRESENTER_TOKEN) private readonly importRaceResultsApiPresenter: ImportRaceResultsApiPresenter, @Inject(RACE_DETAIL_PRESENTER_TOKEN) private readonly raceDetailPresenter: RaceDetailPresenter, @Inject(RACES_PAGE_DATA_PRESENTER_TOKEN) private readonly racesPageDataPresenter: RacesPageDataPresenter, @Inject(ALL_RACES_PAGE_DATA_PRESENTER_TOKEN) private readonly allRacesPageDataPresenter: AllRacesPageDataPresenter, @Inject(RACE_RESULTS_DETAIL_PRESENTER_TOKEN) private readonly raceResultsDetailPresenter: RaceResultsDetailPresenter, @Inject(RACE_WITH_SOF_PRESENTER_TOKEN) private readonly raceWithSOFPresenter: RaceWithSOFPresenter, @Inject(RACE_PROTESTS_PRESENTER_TOKEN) private readonly raceProtestsPresenter: RaceProtestsPresenter, @Inject(RACE_PENALTIES_PRESENTER_TOKEN) private readonly racePenaltiesPresenter: RacePenaltiesPresenter, @Inject(COMMAND_RESULT_PRESENTER_TOKEN) private readonly commandResultPresenter: CommandResultPresenter, ) {} async getAllRaces(): Promise { this.logger.debug('[RaceService] Fetching all races.'); await this.getAllRacesUseCase.execute({}); return this.getAllRacesPresenter; } async getTotalRaces(): Promise { this.logger.debug('[RaceService] Fetching total races count.'); await this.getTotalRacesUseCase.execute({}); return this.getTotalRacesPresenter; } async importRaceResults(input: ImportRaceResultsDTO): Promise { this.logger.debug('Importing race results:', input); await this.importRaceResultsApiUseCase.execute({ raceId: input.raceId, resultsFileContent: input.resultsFileContent }); return this.importRaceResultsApiPresenter; } async getRaceDetail(params: GetRaceDetailParamsDTO): Promise { this.logger.debug('[RaceService] Fetching race detail:', params); await this.getRaceDetailUseCase.execute(params); return this.raceDetailPresenter; } async getRacesPageData(leagueId: string): Promise { this.logger.debug('[RaceService] Fetching races page data.'); await this.getRacesPageDataUseCase.execute({ leagueId }); return this.racesPageDataPresenter; } async getAllRacesPageData(): Promise { this.logger.debug('[RaceService] Fetching all races page data.'); await this.getAllRacesPageDataUseCase.execute({}); return this.allRacesPageDataPresenter; } async getRaceResultsDetail(raceId: string): Promise { this.logger.debug('[RaceService] Fetching race results detail:', { raceId }); await this.getRaceResultsDetailUseCase.execute({ raceId }); return this.raceResultsDetailPresenter; } async getRaceWithSOF(raceId: string): Promise { this.logger.debug('[RaceService] Fetching race with SOF:', { raceId }); await this.getRaceWithSOFUseCase.execute({ raceId }); return this.raceWithSOFPresenter; } async getRaceProtests(raceId: string): Promise { this.logger.debug('[RaceService] Fetching race protests:', { raceId }); await this.getRaceProtestsUseCase.execute({ raceId }); return this.raceProtestsPresenter; } async getRacePenalties(raceId: string): Promise { this.logger.debug('[RaceService] Fetching race penalties:', { raceId }); await this.getRacePenaltiesUseCase.execute({ raceId }); return this.racePenaltiesPresenter; } async registerForRace(params: RegisterForRaceParamsDTO): Promise { this.logger.debug('[RaceService] Registering for race:', params); await this.registerForRaceUseCase.execute(params); return this.commandResultPresenter; } async withdrawFromRace(params: WithdrawFromRaceParamsDTO): Promise { this.logger.debug('[RaceService] Withdrawing from race:', params); await this.withdrawFromRaceUseCase.execute(params); return this.commandResultPresenter; } async cancelRace(params: RaceActionParamsDTO, cancelledById: string): Promise { this.logger.debug('[RaceService] Cancelling race:', params); await this.cancelRaceUseCase.execute({ raceId: params.raceId, cancelledById }); return this.commandResultPresenter; } async completeRace(params: RaceActionParamsDTO): Promise { this.logger.debug('[RaceService] Completing race:', params); await this.completeRaceUseCase.execute({ raceId: params.raceId }); return this.commandResultPresenter; } async reopenRace(params: RaceActionParamsDTO, reopenedById: string): Promise { this.logger.debug('[RaceService] Re-opening race:', params); await this.reopenRaceUseCase.execute({ raceId: params.raceId, reopenedById }); return this.commandResultPresenter; } async fileProtest(command: FileProtestCommandDTO): Promise { this.logger.debug('[RaceService] Filing protest:', command); await this.fileProtestUseCase.execute(command); return this.commandResultPresenter; } async applyQuickPenalty(command: QuickPenaltyCommandDTO): Promise { this.logger.debug('[RaceService] Applying quick penalty:', command); await this.quickPenaltyUseCase.execute(command); return this.commandResultPresenter; } async applyPenalty(command: ApplyPenaltyCommandDTO): Promise { this.logger.debug('[RaceService] Applying penalty:', command); await this.applyPenaltyUseCase.execute(command); return this.commandResultPresenter; } async requestProtestDefense(command: RequestProtestDefenseCommandDTO): Promise { this.logger.debug('[RaceService] Requesting protest defense:', command); await this.requestProtestDefenseUseCase.execute(command); return this.commandResultPresenter; } async reviewProtest(command: ReviewProtestCommandDTO): Promise { this.logger.debug('[RaceService] Reviewing protest:', command); await this.reviewProtestUseCase.execute(command); return this.commandResultPresenter; } }