import { useQuery } from 'react-query';

import { acknowledgementsKeys } from '../queries';
import { getAcknowledgement } from '../services';

export const useGetAcknowledgement = (acknowledgementId?: number) => {
  return useQuery({
    queryKey: acknowledgementsKeys.detail(acknowledgementId),
    queryFn: () => {
      if (!acknowledgementId) throw new Error('Acknowledgement ID is required');
      return getAcknowledgement(acknowledgementId);
    },
    select: response => response.data,
    enabled: !!acknowledgementId,
  });
};
