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

export const getSalesSummaryReport = async (
  filters: SalesSummaryFilters
): Promise<SalesSummaryResponse> => {
  const queryParams: Record<string, string | number | string[]> = {};

  queryParams.from = filters.from;
  queryParams.to = filters.to;

  if (filters.status) queryParams.status = filters.status;
  if (filters.product_sku) queryParams.product_sku = filters.product_sku;
  if (filters.product_name) queryParams.product_name = filters.product_name;
  if (filters.min_quantity !== undefined) queryParams.min_quantity = filters.min_quantity;
  if (filters.max_quantity !== undefined) queryParams.max_quantity = filters.max_quantity;
  if (filters.min_weight !== undefined) queryParams.min_weight = filters.min_weight;
  if (filters.max_weight !== undefined) queryParams.max_weight = filters.max_weight;
  if (filters.min_sales !== undefined) queryParams.min_sales = filters.min_sales;
  if (filters.max_sales !== undefined) queryParams.max_sales = filters.max_sales;
  if (filters.limit !== undefined) queryParams.limit = filters.limit;
  if (filters.offset !== undefined) queryParams.offset = filters.offset;

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