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

/**
 * Approve the whole verification (all required steps pass → aggregate `approved`), removing it from the
 * queue. Takes the `nurseVerificationId`; invalidates the queue and that case so both reflect the flip.
 */
export function useApproveVerification() {
  const queryClient = useQueryClient();
  return useMutation<void, unknown, number>({
    mutationFn: (nurseVerificationId) => verificationApi.approveVerification(nurseVerificationId),
    onSuccess: (_void, nurseVerificationId) => {
      queryClient.invalidateQueries({ queryKey: verificationKeys.adminQueues() });
      queryClient.invalidateQueries({ queryKey: verificationKeys.adminCase(nurseVerificationId) });
    },
  });
}
