import { UseQueryOptions, useInfiniteQuery, useQuery } from '@tanstack/react-query'


export function useSafeQuery<T, K = unknown>(
  queryKey: [string, K?],
  queryFn: () => Promise<T>,
  options?: Omit<UseQueryOptions<T>, 'queryKey' | 'queryFn'>
) {
  return useQuery({
    queryKey,
    queryFn,
    ...options,
  })
}

export function useSafeInfiniteQuery<T, K = unknown>(
  queryKey: [string, K?],
  queryFn: ({ pageParam }: { pageParam: number }) => Promise<T>,
  getNextPageParam: (lastPage: T, allPages: T[]) => number | undefined,
) {
  return useInfiniteQuery({
    queryKey,
    queryFn,
    getNextPageParam,
    initialPageParam: 0,
  })
}