/**
 * Forgot Password Mutation
 *
 * Framework-agnostic mutation for forgot password operations.
 * Called from Server Actions.
 *
 * Pattern: Server Action → Mutation → Service → API Client
 */

import { Result } from '@/lib/contracts/Result';
import { AuthService } from '@/lib/services/auth/AuthService';
import { ForgotPasswordDTO } from '@/lib/types/generated/ForgotPasswordDTO';
import { ForgotPasswordResult } from '@/lib/mutations/auth/types/ForgotPasswordResult';

export class ForgotPasswordMutation {
  async execute(params: ForgotPasswordDTO): Promise<Result<ForgotPasswordResult, string>> {
    try {
      const authService = new AuthService();
      const result = await authService.forgotPassword(params);
      if (result.isErr()) {
        return Result.err(result.getError().message);
      }
      return Result.ok(result.unwrap());
    } catch (error: any) {
      const errorMessage = error instanceof Error ? error.message : 'Failed to send reset link';
      return Result.err(errorMessage);
    }
  }
}
