import { useQuery } from "@tanstack/react-query";
import { queryKeys } from "../queryKeys";

interface SystemInfo {
  version?: string;
  db_path?: string;
}

interface LoopsInfo {
  active_count: number;
}

export function useSystemInfo() {
  return useQuery({
    queryKey: queryKeys.system.info,
    queryFn: async (): Promise<SystemInfo> => {
      const res = await fetch("/api/system-info");
      return res.json();
    },
    staleTime: 60_000,
    refetchInterval: 60_000,
  });
}

export function useLoops() {
  return useQuery({
    queryKey: queryKeys.system.loops,
    queryFn: async (): Promise<LoopsInfo> => {
      const res = await fetch("/api/loops");
      return res.json();
    },
  });
}
