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

type PrivacyPolicyResponse = {
  content: string;
};

export default function useFetchPrivacyPolicy() {
  const { data, isLoading, error, isError } = useQuery({
    queryKey: ["privacy-policy"],
    queryFn: async () => {
      const response = await apiGet<PrivacyPolicyResponse>(
        PUBLIC_SETTINGS.GET_PRIVACY_POLICY,
      );
      return response.data;
    },
    staleTime: 30 * 60 * 1000,
    gcTime: 60 * 60 * 1000,
  });

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