import { useQuery as useQueryTanstack } from "@tanstack/react-query";
import { queryFetcher } from "./request";

export const REFETCH_INTERVAL_XS = 1_000;
export const REFETCH_INTERVAL_S = 5_000;
export const REFETCH_INTERVAL_L = 120_000;

export const useQuery = <T>({
  queryKey,
  refetchInterval = REFETCH_INTERVAL_S,
  isEnabled = true,
}: {
  queryKey: string;
  refetchInterval?: number;
  isEnabled?: boolean;
}) => {
  return useQueryTanstack({
    queryKey: [queryKey],
    queryFn: queryFetcher<T>,
    refetchOnWindowFocus: true,
    refetchInterval,
    enabled: isEnabled,
  });
};
