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

type PaymentSettingsResponse = {
  stripePublishableKey: string;
  stripeSecretKey: string;
  stripeWebhookSecret: string;
};

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

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