import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { QUERY_KEYS } from "@/utils/query-key";
import toast from "react-hot-toast";
import { getPaymentCard, updatePaymentCard } from "./_requests";
import { UpdatePaymentCardRequest } from "./_models";

export const usePaymentCard = () => {
  return useQuery({
    queryKey: [QUERY_KEYS.GET_PAYMENT_CARD],
    queryFn: getPaymentCard,
  });
};

export const useUpdatePaymentCard = () => {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: (payload: UpdatePaymentCardRequest) => updatePaymentCard(payload),
    onSuccess: () => {
      queryClient.invalidateQueries({
        queryKey: [QUERY_KEYS.GET_PAYMENT_CARD],
      });
      toast.success("اطلاعات کارت با موفقیت به‌روزرسانی شد");
    },
    onError: (error: any) => {
      toast.error(error?.message || "خطا در به‌روزرسانی اطلاعات کارت");
    },
  });
};







