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

import { mapsQueryKeys } from '../maps-query-keys';
import { mapsApi, type PostGetSizeForBoundingBox } from '../maps-api';

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

export const usePostGetSizeForBoundingBoxQuery = (
  token: string,
  bbox_array: number[], // [minLon, minLat, maxLon, maxLat] JSON string
  enabled: boolean
) => {
  return useQuery<PostGetSizeForBoundingBox, BaseAxiosError>({
    queryKey: mapsQueryKeys.getSizeForBoundingBox(token, bbox_array),
    queryFn: async () => {
      const response = await mapsApi.getSizeForBoundingBox(token, bbox_array);
      return response.data;
    },
    enabled
  });
};
