import { httpGetRequest, APIUrlGenerator } from "@/utils/baseHttpService";
import { API_ROUTES } from "@/constant/routes";
import {
  SalesGrowthFilters,
  SalesGrowthResponse,
  UserRegistrationGrowthFilters,
  UserRegistrationGrowthResponse,
  SalesByCategoryFilters,
  SalesByCategoryResponse,
} from "./_models";

export const getSalesGrowthReport = async (
  filters?: SalesGrowthFilters
): Promise<SalesGrowthResponse> => {
  const queryParams: Record<string, string | number | null> = {};

  if (filters?.group_by) queryParams.group_by = filters.group_by;
  if (filters?.status) queryParams.status = filters.status;
  if (filters?.from) queryParams.from = filters.from;
  if (filters?.to) queryParams.to = filters.to;

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

export const getUserRegistrationGrowthReport = async (
  filters?: UserRegistrationGrowthFilters
): Promise<UserRegistrationGrowthResponse> => {
  const queryParams: Record<string, string | number | null> = {};

  if (filters?.group_by) queryParams.group_by = filters.group_by;
  if (filters?.from) queryParams.from = filters.from;
  if (filters?.to) queryParams.to = filters.to;

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

export const getSalesByCategoryReport = async (
  filters?: SalesByCategoryFilters
): Promise<SalesByCategoryResponse> => {
  const queryParams: Record<string, string | number | null> = {};

  if (filters?.status) queryParams.status = filters.status;
  if (filters?.from) queryParams.from = filters.from;
  if (filters?.to) queryParams.to = filters.to;

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