import showCustomToast from "@/components/common/toaster/CustomToast";
import { UpdatePassword } from "@/lib/services/auth.services";
import { UpdatePasswordType } from "@/type/authType";
import { useMutation } from "@tanstack/react-query";

export const useUpdatePassword = () => {
  const { mutate: updatePassword, isSuccess } = useMutation({
    mutationFn: async (data: UpdatePasswordType) => await UpdatePassword(data),
    onSuccess: (response) => {
      // Handle success, e.g., show a success message

      showCustomToast({
        message: response.message || "Password updated successfully",
        type: "success",
      });
    },
    onError: (error) => {
      // Handle error, e.g., show an error message
      showCustomToast({
        message: error.message || "Failed to update password",
        type: "error",
      });
    },
  });

  return { updatePassword, isSuccess };
};
