"use client";

import { useMutation } from "@tanstack/react-query";
import { verifyOtpApi } from "@/lib/api/auth.api";
import type { VerifyOtpRequest, VerifyOtpResponse } from "@/types/auth";

/**
 * Verifies a phone OTP. Unlike login, registration verifies the code as its own
 * step (the backend sets a Redis "verified" flag that `provider/register` later
 * requires). Errors are surfaced inline by the caller (near the OTP field), so
 * this hook intentionally does not toast — the caller reads `error`/`isError`.
 */
export function useVerifyOtp(options?: {
  onSuccess?: (data: VerifyOtpResponse) => void;
}) {
  return useMutation({
    mutationFn: (payload: VerifyOtpRequest) => verifyOtpApi(payload),
    onSuccess: (data) => {
      options?.onSuccess?.(data);
    },
  });
}
