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

/**
 * Makes an account the payout primary; single-primary enforcement is server-side (the prior
 * primary is cleared atomically). Invalidates the list so the cache reflects the switch.
 */
export function useSetPrimaryBankAccount() {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: (id: number) => nurseBankApi.setPrimary(id),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: bankKeys.list() });
    },
  });
}
