import { Result } from '@/lib/contracts/Result'; import { ProtestService } from '@/lib/services/protests/ProtestService'; import { ProtestsApiClient } from '@/lib/api/protests/ProtestsApiClient'; import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter'; import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger'; import type { ApplyPenaltyCommandDTO } from '@/lib/types/generated/ApplyPenaltyCommandDTO'; import type { RequestProtestDefenseCommandDTO } from '@/lib/types/generated/RequestProtestDefenseCommandDTO'; /** * ProtestReviewMutation * * Framework-agnostic mutation for protest review operations. * Can be called from Server Actions or other contexts. */ export class ProtestReviewMutation { private service: ProtestService; constructor() { // Manual wiring for serverless const baseUrl = process.env.NEXT_PUBLIC_API_URL || ''; const errorReporter = new ConsoleErrorReporter(); const logger = new ConsoleLogger(); const apiClient = new ProtestsApiClient(baseUrl, errorReporter, logger); this.service = new ProtestService(apiClient); } async applyPenalty(input: ApplyPenaltyCommandDTO): Promise> { try { await this.service.applyPenalty(input); return Result.ok(undefined); } catch (error) { console.error('applyPenalty failed:', error); return Result.err('Failed to apply penalty'); } } async requestDefense(input: RequestProtestDefenseCommandDTO): Promise> { try { await this.service.requestDefense(input); return Result.ok(undefined); } catch (error) { console.error('requestDefense failed:', error); return Result.err('Failed to request defense'); } } async reviewProtest(input: { protestId: string; stewardId: string; decision: string; decisionNotes: string }): Promise> { try { await this.service.reviewProtest(input as any); return Result.ok(undefined); } catch (error) { console.error('reviewProtest failed:', error); return Result.err('Failed to review protest'); } } }