import { useMutation, useQueryClient } from '@tanstack/react-query';
import { verificationApi } from '../apis';
import { verificationKeys } from '../keys';

/**
 * Runs the استعلام شبا IBAN-owner ↔ national-id match (money-mule guard) for the
 * `bank_account_verification` step. Requires a verified identity + a primary bank account (added on the
 * f2 bank screen this checklist deep-links to) — a `400` otherwise, surfaced inline. Invalidates the
 * status so the checklist reflects the step's new state.
 */
export function useRunBankVerification() {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: () => verificationApi.runBankVerification(),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: verificationKeys.status() });
    },
  });
}
