import { useQuery } from '@tanstack/react-query';

import { eventsQueryKeys } from '../events-query-keys';
import { eventsApi, type PostGetEventsListReturn } from '../events-api';

import type { BaseAxiosError } from '../../../../types';

export const useGetEventsListQuery = (token: string, past: 0 | 1, enabled: boolean) => {
  return useQuery<PostGetEventsListReturn, BaseAxiosError>({
    queryKey: eventsQueryKeys.getEventsList(token, past),
    queryFn: async () => {
      const response = await eventsApi.getEventsList(token, past);
      return response.data;
    },
    enabled
  });
};
