/* eslint-disable @typescript-eslint/no-unused-vars */ import { type UseQueryOptions, useQuery } from "@tanstack/react-query"; import type { K8sResource, K8sResourceList, KubectlContexts, } from "./interfaces"; import apiService from "./apiService"; // Get list of kubectl contexts configured locally function useGetKubectlContexts(options?: UseQueryOptions) { return useQuery({ queryKey: ["k8s", "contexts"], queryFn: () => apiService.fetchWithSafeDefaults({ url: "/api/k8s/contexts", fallback: { contexts: [] }, }), ...(options ?? {}), }); } // Get resources information function useGetK8sResource( kind: string, name: string, namespace: string, options?: UseQueryOptions ) { return useQuery({ queryKey: ["k8s", kind, "get", name, namespace], queryFn: () => apiService.fetchWithSafeDefaults({ url: `/api/k8s/${kind}/get?name=${name}&namespace=${namespace}`, fallback: { kind: "", name: "", namespace: "" }, }), ...(options ?? {}), }); } // Get list of resources function useGetK8sResourceList( kind: string, options?: UseQueryOptions ) { return useQuery({ queryKey: ["k8s", kind, "list"], queryFn: () => apiService.fetchWithSafeDefaults({ url: `/api/k8s/${kind}/list`, fallback: { items: [] }, }), ...(options ?? {}), }); } // Get describe text for kubernetes resource function useGetK8sResourceDescribe( kind: string, name: string, namespace: string, options?: UseQueryOptions ) { return useQuery({ queryKey: ["k8s", kind, "describe", name, namespace], queryFn: () => apiService.fetchWithDefaults( `/api/k8s/${kind}/describe?name=${name}&namespace=${namespace}`, { headers: { Accept: "text/plain", }, } ), ...(options ?? {}), }); }