import { useMutation } from '@tanstack/react-query';

import { authApi } from '../apis';
import type { OtpRequest } from '../types';

/**
 * Request an OTP for a phone (A1/B1 → A2/B2). Domain 4xx (400 invalid phone, 429 rate-limit)
 * surface via `mutation.error` for the caller to render inline — 401/403/5xx are already
 * toasted by the fetch layer, so this hook does not toast.
 */
export function useRequestOtp() {
  return useMutation({
    mutationFn: (body: OtpRequest) => authApi.requestOtp(body),
  });
}
