import { useQuery } from "@tanstack/react-query";
import axiosInstance from "@/lib/axios";

// Fetcher that accepts `input` as a parameter
const fetchUserContact = async (id?: number) => {
  const userId = localStorage.getItem("userId");

  const { data } = await axiosInstance.get(`/users/${userId || id}/contact`);

  return data;
};

export const useGetUserContact = (userId?: number) => {
  return useQuery({
    queryKey: ["userContact", userId],
    queryFn: () => fetchUserContact(userId),
    staleTime: 1000 * 60 * 10,
    refetchOnWindowFocus: false,
  });
};
