import { useQuery } from 'react-query';

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

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

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

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

export default useGetSessionsStats;
