import { Result } from '@/lib/contracts/Result';
import { ProtestService } from '@/lib/services/protests/ProtestService';
import type { ApplyPenaltyCommandDTO } from '@/lib/types/generated/ApplyPenaltyCommandDTO';
import type { RequestProtestDefenseCommandDTO } from '@/lib/types/generated/RequestProtestDefenseCommandDTO';
import { DomainError } from '@/lib/contracts/services/Service';

/**
 * ProtestReviewMutation
 * 
 * Framework-agnostic mutation for protest review operations.
 * Can be called from Server Actions or other contexts.
 */
export class ProtestReviewMutation {
  private service: ProtestService;

  constructor() {
    this.service = new ProtestService();
  }

  async applyPenalty(input: ApplyPenaltyCommandDTO): Promise<Result<void, DomainError>> {
    try {
      return await this.service.applyPenalty(input);
    } catch (error: unknown) {
      console.error('applyPenalty failed:', error);
      return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to apply penalty' });
    }
  }

  async requestDefense(input: RequestProtestDefenseCommandDTO): Promise<Result<void, DomainError>> {
    try {
      return await this.service.requestDefense(input);
    } catch (error: unknown) {
      console.error('requestDefense failed:', error);
      return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to request defense' });
    }
  }

  async reviewProtest(input: { protestId: string; stewardId: string; decision: string; decisionNotes: string }): Promise<Result<void, DomainError>> {
    try {
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      return await this.service.reviewProtest(input as any);
    } catch (error: unknown) {
      console.error('reviewProtest failed:', error);
      return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to review protest' });
    }
  }
}
