import { useQuery } from 'react-query';

import { getShiftRotationById } from 'src/services/shifts';

import { shiftsKeys } from '../queries';

export const useGetShiftRotationById = (id: string | undefined) => {
  const { data, isLoading, isError } = useQuery({
    queryKey: shiftsKeys.shiftRotation(id ?? ''),
    queryFn: () => getShiftRotationById(id as string),
    enabled: !!id,
    staleTime: 1000 * 60 * 2,
  });

  return {
    rotation: data?.data,
    isLoading: !!id && isLoading,
    isError,
  };
};
