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

import { regionsQueryKeys } from '../regions-query-keys';
import { regionsApi, type PostGetVisitsReturn } from '../regions-api';

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

export const useGetVisitsQuery = (region: number, token: string, enabled: boolean) => {
  return useQuery<PostGetVisitsReturn, BaseAxiosError>({
    queryKey: regionsQueryKeys.getVisits(token, region),
    queryFn: async () => {
      const response = await regionsApi.getVisits(token, region);
      return response.data;
    },
    enabled
  });
};
