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

import { searchQueryKeys } from '../search-query-keys';
import { searchApi, type PostGetUniversalReturn } from '../search-api';

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

export const useGetUniversalSearch = (search: string, enabled: boolean) => {
  return useQuery<PostGetUniversalReturn, BaseAxiosError>({
    queryKey: searchQueryKeys.getUniversal(search),
    queryFn: async () => {
      const response = await searchApi.getUniversal(search);
      return response.data;
    },
    enabled
  });
};
