import { useQuery } from 'react-query';

import { getPath } from 'src/pages/dashboard/Learning/Paths/services';
import { sToMs } from 'src/utils/timeUtils';

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

const useGetPath = (pathId: number | null) => {
  return useQuery({
    queryKey: pathsKeys.detail(pathId!),
    queryFn: () => {
      if (!pathId) throw new Error('Path ID is required');
      return getPath(pathId);
    },
    enabled: !!pathId,
    select: res => res.data,
    staleTime: sToMs(60),
  });
};

export default useGetPath;
