import { useMutation } from '@tanstack/react-query';
import { bnplApi } from '../apis';
import type { CheckEligibilityInput } from '../types';

/**
 * D3 — the provider credit check. The consent checkbox gates the submit at the call site (no consent, no
 * mutation). The result (`eligible` / `not_eligible` / `ceiling_exceeded`) drives the D3 panel; a declined
 * verdict is not an error — it renders the declined panel + the card fall-back, not a toast. The fetch
 * layer owns 401/403/5xx; only domain 4xx (e.g. a token-expired) would surface inline via `mutation.error`.
 */
export function useCheckEligibility() {
  return useMutation({
    mutationFn: (input: CheckEligibilityInput) => bnplApi.checkEligibility(input),
  });
}
