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

export interface RejectVerificationVars {
  nurseVerificationId: number;
  reason: string;
}

/**
 * Reject the whole verification (aggregate `rejected`), removing it from the queue. Takes the
 * `nurseVerificationId` + a `reason`; invalidates the queue and that case so both reflect the change.
 */
export function useRejectVerification() {
  const queryClient = useQueryClient();
  return useMutation<void, unknown, RejectVerificationVars>({
    mutationFn: ({ nurseVerificationId, reason }) => verificationApi.rejectVerification(nurseVerificationId, reason),
    onSuccess: (_void, { nurseVerificationId }) => {
      queryClient.invalidateQueries({ queryKey: verificationKeys.adminQueues() });
      queryClient.invalidateQueries({ queryKey: verificationKeys.adminCase(nurseVerificationId) });
    },
  });
}
