import { Inject, Injectable } from '@nestjs/common';
import type { Logger } from '@core/shared/application/Logger';

// Use cases
import { ReviewProtestUseCase } from '@core/racing/application/use-cases/ReviewProtestUseCase';

// Presenter
import { ReviewProtestPresenter, type ReviewProtestResponseDTO } from './presenters/ReviewProtestPresenter';

// Tokens
import { LOGGER_TOKEN, REVIEW_PROTEST_PRESENTER_TOKEN } from './ProtestsProviders';


@Injectable()
export class ProtestsService {
  constructor(
    private readonly reviewProtestUseCase: ReviewProtestUseCase,
    @Inject(REVIEW_PROTEST_PRESENTER_TOKEN) private readonly reviewProtestPresenter: ReviewProtestPresenter,
    @Inject(LOGGER_TOKEN) private readonly logger: Logger,
  ) {}

  async reviewProtest(command: {
    protestId: string;
    stewardId: string;
    decision: 'uphold' | 'dismiss';
    decisionNotes: string;
  }): Promise<ReviewProtestResponseDTO> {
    this.logger.debug('[ProtestsService] Reviewing protest:', command);

    // Set the command on the presenter so it can include stewardId and decision in the response
    this.reviewProtestPresenter.setCommand({
      stewardId: command.stewardId,
      decision: command.decision,
    });

    await this.reviewProtestUseCase.execute(command);

    return this.reviewProtestPresenter.responseModel;
  }
}