import { useQuery } from "@tanstack/react-query";
import { QUERY_KEYS } from "@/utils/query-key";
import {
  getDiscountUsageReport,
  getCustomerDiscountUsageReport,
} from "./_requests";
import {
  DiscountUsageFilters,
  CustomerDiscountUsageFilters,
} from "./_models";

export const useDiscountUsageReport = (filters: DiscountUsageFilters) => {
  return useQuery({
    queryKey: [QUERY_KEYS.GET_DISCOUNT_USAGE_REPORT, filters],
    queryFn: () => getDiscountUsageReport(filters),
    enabled: filters.limit > 0,
  });
};

export const useCustomerDiscountUsageReport = (
  filters: CustomerDiscountUsageFilters & { _refetchKey?: number }
) => {
  const { _refetchKey, ...cleanFilters } = filters;
  return useQuery({
    queryKey: [QUERY_KEYS.GET_CUSTOMER_DISCOUNT_USAGE_REPORT, cleanFilters, _refetchKey],
    queryFn: () => getCustomerDiscountUsageReport(cleanFilters),
    enabled: cleanFilters.user_id > 0 && cleanFilters.limit > 0,
  });
};

