import { useQuery } from "@tanstack/react-query";
import { apiGet } from "../../../lib/api/methods";
import { API_KEYS_ENDPOINTS } from "./endpoints";

export type ApiKeyResponse = {
  apiKey: string;
  createdAt: string;
  lastUsedAt: string;
};

export default function useApiKeysFetch() {
  const { data, isFetching, isError, error } = useQuery({
    queryKey: ["api-keys"],
    queryFn: async () => {
      const res = await apiGet<ApiKeyResponse>(API_KEYS_ENDPOINTS.API_KEYS);
      return res.data;
    },
    staleTime: 5 * 60 * 1000,
  });

  return { apiKeys: data, loading: isFetching, error, isError };
}
