import { useUserProfileStore } from "../context/zustand-store/userStore";
import { useApiMutation } from "../utils/useApiRequest";

export const useFetchProfile = () => {
  const setUserProfile = useUserProfileStore((s) => s.setUserProfile);

  const mutationProfile = useApiMutation({
    api: "/auth/api/v1/user/profile/",
    method: "get",
    disableBackdrop: true,
  });

  const getProfile = async () => {
    const profile = await mutationProfile.mutateAsync({});
    if (typeof profile === "object") {
      setUserProfile(profile);
    }
  };

  return { getProfile };
};
