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

type TermsAndConditionsResponse = {
  content: string;
};

export default function useFetchTermsAndConditions() {
  const { data, isLoading, error, isError } = useQuery({
    queryKey: ["terms-and-conditions"],
    queryFn: async () => {
      const response = await apiGet<TermsAndConditionsResponse>(
        PUBLIC_SETTINGS.GET_TERMS,
      );
      return response.data;
    },
    staleTime: 30 * 60 * 1000,
    gcTime: 60 * 60 * 1000,
  });

  return {
    content: data?.content,
    loading: isLoading,
    error,
    isError,
  };
}
