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

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

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

export const useGetRegionQeQuery = (megaregion: number, token: string, enabled: boolean) => {
  return useQuery<PostGetRegionsQeReturn, BaseAxiosError>({
    queryKey: regionsQueryKeys.getRegionsQe(megaregion, token),
    queryFn: async () => {
      const response = await regionsApi.getRegionsQe(megaregion, token);
      return response.data;
    },
    enabled
  });
};
