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

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

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

export const useGetRegionsWithFlagQuery = (enabled: boolean) => {
  return useQuery<PostGetRegionsReturn, BaseAxiosError>({
    queryKey: regionQueryKeys.getRegions(),
    queryFn: async () => {
      const response = await regionsApi.getRegionsWithFlag();
      return response.data;
    },
    enabled
  });
};
