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

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

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

export const useGetListRegionsQuery = (enabled: boolean) => {
  return useQuery<PostGetListRegionsReturn, BaseAxiosError>({
    queryKey: regionQueryKeys.getListRegions(),
    queryFn: async () => {
      const response = await regionsApi.getListRegions();
      return response.data;
    },
    enabled
  });
};
