import axios from "@/config/axios";
import { BrandResponse, BrandProductsParams } from "../types/Types";

export const getBrandProducts = async (
  params: BrandProductsParams
): Promise<BrandResponse> => {
  const {
    brandId,
    page = 1,
    limit = 10,
    sort,
    priceMin,
    priceMax,
    category,
  } = params;

  const queryParams = new URLSearchParams({
    page: page.toString(),
    limit: limit.toString(),
  });

  if (sort) queryParams.append("sort", sort.toString());
  if (priceMin) queryParams.append("priceMin", priceMin.toString());
  if (priceMax) queryParams.append("priceMax", priceMax.toString());
  if (category) queryParams.append("category", category);

  const { data } = await axios.get<BrandResponse>(
    `/brand/${brandId}/search?${queryParams.toString()}`
  );
  return data;
};
