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

import { seriesQueryKeys } from '../series-query-keys';
import { seriesApi, type PostGetDataFromPoint } from '../series-api';

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

export const useGetDataFromPoint = (token: string, lat: number, lng: number, enabled: boolean) => {
  return useQuery<PostGetDataFromPoint, BaseAxiosError>({
    queryKey: seriesQueryKeys.getDataFromPoint(token, lat, lng),
    queryFn: async () => {
      const response = await seriesApi.getDataFromPoint(token, lat, lng);
      return response.data;
    },
    enabled
  });
};
