import type { ReviewProtestApplicationError, ReviewProtestResult } from '@core/racing/application/use-cases/ReviewProtestUseCase';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';

export interface ReviewProtestResponseDTO {
  success: boolean;
  errorCode?: string;
  message?: string;
  protestId?: string;
  stewardId?: string;
  decision?: 'uphold' | 'dismiss';
}

export class ReviewProtestPresenter implements UseCaseOutputPort<ReviewProtestResult> {
  private model: ReviewProtestResponseDTO | null = null;

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

  present(result: ReviewProtestResult, context?: { stewardId: string; decision: 'uphold' | 'dismiss' }): void {
    if (!context) {
      throw new Error('Context must be provided when presenting result');
    }
    
    this.model = {
      success: true,
      protestId: result.protestId,
      stewardId: context.stewardId,
      decision: context.decision,
    };
  }

  presentError(error: ReviewProtestApplicationError): void {
    this.model = {
      success: false,
      errorCode: error.code,
      message: error.details.message,
    };
  }

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

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

    return this.model;
  }
}
