import { httpGetRequest, APIUrlGenerator } from "@/utils/baseHttpService";
import { API_ROUTES } from "@/constant/routes";
import { VariantComparisonFilters, VariantComparisonResponse } from "./_models";

export const getVariantComparisonReport = async (
  filters?: VariantComparisonFilters
): Promise<VariantComparisonResponse> => {
  const queryParams: Record<string, string | number | boolean> = {};

  if (filters?.product_id !== undefined) queryParams.product_id = filters.product_id;
  if (filters?.product_sku) queryParams.product_sku = filters.product_sku;
  if (filters?.variant_color) queryParams.variant_color = filters.variant_color;
  if (filters?.variant_size) queryParams.variant_size = filters.variant_size;
  if (filters?.enabled !== undefined) queryParams.enabled = filters.enabled;
  if (filters?.min_stock !== undefined) queryParams.min_stock = filters.min_stock;
  if (filters?.max_stock !== undefined) queryParams.max_stock = filters.max_stock;
  if (filters?.has_stock !== undefined) queryParams.has_stock = filters.has_stock;
  if (filters?.min_fee_difference !== undefined) queryParams.min_fee_difference = filters.min_fee_difference;
  if (filters?.max_fee_difference !== undefined) queryParams.max_fee_difference = filters.max_fee_difference;
  if (filters?.limit !== undefined) queryParams.limit = filters.limit;
  if (filters?.offset !== undefined) queryParams.offset = filters.offset;

  const response = await httpGetRequest<VariantComparisonResponse>(
    APIUrlGenerator(API_ROUTES.VARIANT_COMPARISON_REPORT, queryParams)
  );
  return response.data;
};
