import { useQuery } from "@tanstack/react-query";
import {
	fetchAlertmanagerAlerts,
	fetchAlertmanagerStatus,
	fetchPrometheusStatus,
	fetchPrometheusTargets,
	fetchMonitoringMachines,
} from "../api/client";

export function useAlertmanagerAlerts() {
	return useQuery({
		queryKey: ["observability", "alerts"],
		queryFn: fetchAlertmanagerAlerts,
		retry: 2,
		staleTime: 10_000,
		refetchInterval: 15_000,
	});
}

export function useAlertmanagerStatus() {
	return useQuery({
		queryKey: ["observability", "alertmanager-status"],
		queryFn: fetchAlertmanagerStatus,
		retry: 2,
		staleTime: 10_000,
		refetchInterval: 30_000,
	});
}

export function usePrometheusStatus() {
	return useQuery({
		queryKey: ["observability", "prometheus-status"],
		queryFn: fetchPrometheusStatus,
		retry: 2,
		staleTime: 10_000,
		refetchInterval: 30_000,
	});
}

export function usePrometheusTargets() {
	return useQuery({
		queryKey: ["observability", "prometheus-targets"],
		queryFn: fetchPrometheusTargets,
		retry: 2,
		staleTime: 10_000,
		refetchInterval: 30_000,
	});
}

export function useMonitoringMachines() {
	return useQuery({
		queryKey: ["monitoring", "machines"],
		queryFn: fetchMonitoringMachines,
		retry: 2,
		staleTime: 10_000,
		refetchInterval: 30_000,
	});
}
