import { useQuery } from 'react-query';

import { getPathsStats } from 'src/pages/dashboard/Learning/Paths/services';
import { type RequestError, type RequestSuccess } from 'src/types/services';
import { sToMs } from 'src/utils/timeUtils';

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

export type TSuccess = RequestSuccess<typeof getPathsStats>;
export type TError = RequestError;
export type TData = TSuccess['data'];

const useGetPathsStats = () => {
  return useQuery<TSuccess, TError, TData>({
    queryKey: pathsKeys.stats(),
    queryFn: () => getPathsStats(),
    select: response => response.data,
    staleTime: sToMs(60),
  });
};

export default useGetPathsStats;
