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

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

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

export const useGetEventQuery = (token: string, url: string, enabled: boolean) => {
  return useQuery<PostGetEventReturn, BaseAxiosError>({
    queryKey: eventsQueryKeys.getEvent(token, url),
    queryFn: async () => {
      const response = await eventsApi.getEvent(token, url);
      return response.data;
    },
    enabled
  });
};
