import axios from "@/config/axios";
import { ProductDetailResponse } from "@/types/product.types";
import {
  AddCommentProps,
  AddQuestionProps,
  SubmitReportProps,
  PriceHistoryResponse,
  ProductQuestionsResponse,
  SaveReportTypes,
} from "../types/Types";

export const getProduct = async (
  id: string
): Promise<ProductDetailResponse> => {
  const { data } = await axios.get(`/product/${id}`);
  return data;
};

export const addComment = async (params: AddCommentProps) => {
  const { data } = await axios.post(
    `/product/${params.productId}/comments`,
    params
  );
  return data;
};

export const addQuestion = async (params: AddQuestionProps) => {
  const { data } = await axios.post(
    `/product/${params.productId}/questions`,
    params
  );
  return data;
};

export const checkWishProduct = async (
  productId: string,
  variantId: string
) => {
  const { data } = await axios.get(
    `/product/${productId}/wishlist/${variantId}`
  );
  return data;
};

export const getPriceHistory = async (
  productId: string
): Promise<PriceHistoryResponse> => {
  const { data } = await axios.get(`/product/${productId}/price-history`);
  return data;
};

export const getProductQuestion = async (
  productId: string
): Promise<ProductQuestionsResponse> => {
  const { data } = await axios.get(`/product/${productId}/report/questions`);
  return data;
};

export const submitReport = async (params: SubmitReportProps) => {
  const { data } = await axios.post(`/product/${params.productId}/report`, {
    questionIds: params.questionIds,
    description: params.description,
  });
  return data;
};

export const saveReport = async (params: SaveReportTypes) => {
  const { data } = await axios.post(
    `/product/${params.productId}/report/save`,
    params
  );
  return data;
};
