import axios from "@/config/axios";
import { ProductsResponse } from "@/types/products.types";
import { WishListType } from "../types/Types";

export const getProducts = async (params?: {
  page?: number;
  limit?: number;
  category?: string;
  brand?: string;
  minPrice?: number;
  maxPrice?: number;
  attributes?: string[];
  sizes?: number[];
  meterages?: number[];
  sort?: string;
  wholeSale?: string;
  stock?: string;
  rating?: number;
}): Promise<ProductsResponse> => {
  const { data } = await axios.get("/category/Organic-supermarket/search", {
    params,
  });
  return data;
};

export const getCategoryProducts = async (
  categoryUrl: string,
  params?: {
    page?: number;
    limit?: number;
    brand?: string;
    minPrice?: number;
    maxPrice?: number;
    attributes?: string[];
    sizes?: number[];
    meterages?: number[];
    sort?: string;
    wholeSale?: string;
    stock?: string;
    category?: string;
    rating?: number;
  }
): Promise<ProductsResponse> => {
  const { data } = await axios.get(`/category/${categoryUrl}/search`, {
    params,
  });
  return data;
};

export const addWishlist = async (params: WishListType) => {
  const { data } = await axios.post(
    `/product/${params.productId}/wishlist/add`,
    params
  );
  return data;
};

export const removeWishlist = async (params: WishListType) => {
  const { data } = await axios.post(
    `/product/${params.productId}/wishlist/remove`,
    params
  );
  return data;
};
