import axios from "@/config/axios";

import { CompareResponse } from "../types/Types";

export const getCompare = async (
  productIds: string[]
): Promise<CompareResponse> => {
  console.log("API call - productIds:", productIds);

  // روش اول: ارسال آرایه به صورت جداگانه
  const params = new URLSearchParams();
  productIds.forEach((id) => {
    params.append("productIds", id);
  });

  console.log("Final URL:", `/product/compare?${params.toString()}`);

  const { data } = await axios.get(`/product/compare?${params.toString()}`);
  console.log("API response:", data);
  return data;
};

export const searchComparProduct = async (productId?: string) => {
  const { data } = await axios.get(
    `/product/compare/search?productId=${productId}`
  );
  return data;
};
