import { Result } from '@/lib/contracts/Result'; import { ProtestService } from '@/lib/services/protests/ProtestService'; import { DomainError } from '@/lib/contracts/services/Service'; import type { Mutation } from '@/lib/contracts/mutations/Mutation'; export interface ApplyPenaltyCommand { protestId: string; penaltyType: string; penaltyValue: number; stewardNotes: string; raceId: string; accusedDriverId: string; reason: string; } export interface RequestDefenseCommand { protestId: string; stewardId: string; } export interface ReviewProtestCommand { protestId: string; stewardId: string; decision: string; decisionNotes: string; } export class ProtestReviewMutation implements Mutation { private readonly service: ProtestService; constructor() { this.service = new ProtestService(); } async execute(_input: ApplyPenaltyCommand | RequestDefenseCommand | ReviewProtestCommand): Promise> { // This class has multiple entry points in its original design, // but to satisfy the Mutation interface we provide a generic execute. // However, the tests call the specific methods directly. return Result.err({ type: 'notImplemented', message: 'Use specific methods' }); } async applyPenalty(input: ApplyPenaltyCommand): Promise> { try { const result = await this.service.applyPenalty(input); if (result.isErr()) { return Result.err(result.getError()); } return Result.ok(undefined); } catch (error) { console.error('applyPenalty failed:', error); return Result.err({ type: 'serverError', message: error instanceof Error ? error.message : 'Unknown error', }); } } async requestDefense(input: RequestDefenseCommand): Promise> { try { const result = await this.service.requestDefense(input); if (result.isErr()) { return Result.err(result.getError()); } return Result.ok(undefined); } catch (error) { console.error('requestDefense failed:', error); return Result.err({ type: 'serverError', message: error instanceof Error ? error.message : 'Unknown error', }); } } async reviewProtest(input: ReviewProtestCommand): Promise> { try { const result = await this.service.reviewProtest(input); if (result.isErr()) { return Result.err(result.getError()); } return Result.ok(undefined); } catch (error) { console.error('reviewProtest failed:', error); return Result.err({ type: 'serverError', message: error instanceof Error ? error.message : 'Unknown error', }); } } }