import { useMutation, useQuery } from "@tanstack/react-query";
import * as api from "../service/Service";
import { useSharedStore } from "@/share/store/sharedStore";

export const useGetDetailProduct = (id: string) => {
  return useQuery({
    queryKey: ["product", id],
    queryFn: () => api.getProduct(id),
  });
};

export const getProductQueryOptions = (id: string) => ({
  queryKey: ["product", id],
  queryFn: () => api.getProduct(id),
});

export const useAddComment = () => {
  return useMutation({
    mutationFn: api.addComment,
  });
};

export const useAddQuestion = () => {
  return useMutation({
    mutationFn: api.addQuestion,
  });
};

export const useCheckWishProduct = (productId: string, variantId: string) => {
  const { isLogin } = useSharedStore();
  return useQuery({
    queryKey: ["check-wish-product", productId, variantId],
    queryFn: () => api.checkWishProduct(productId, variantId),
    enabled: !!productId && !!variantId && isLogin,
  });
};

export const useGetPriceHistory = (productId: string) => {
  return useQuery({
    queryKey: ["price-history", productId],
    queryFn: () => api.getPriceHistory(productId),
    enabled: !!productId,
  });
};

export const useGetProductQuestion = (productId: string) => {
  return useQuery({
    queryKey: ["product-question", productId],
    queryFn: () => api.getProductQuestion(productId),
    enabled: !!productId,
  });
};

export const useSaveReport = () => {
  return useMutation({
    mutationFn: api.saveReport,
  });
};
