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

type SightEngineSettingsResponse = {
  apiUser: string;
  apiSecret: string;
  imageDetection: boolean;
};

export default function useFetchSightEngineSettings() {
  const { data, isPending, isError, error } = useQuery({
    queryKey: ["sight-engine-settings"],
    queryFn: async () => {
      const response = await apiGet<SightEngineSettingsResponse>(
        SETTINGS_ENDPOINTS.SIGHT_ENGINE,
      );
      return response.data;
    },
    staleTime: 10 * 60 * 1000,
  });

  return {
    sightEngineSettings: data,
    loading: isPending,
    isError,
    error,
  };
}
