import { ExtractFilterValue, FiltersMap } from '@wix/bex-core';

export const transformCustomNumberRangeFilterToWQL = <F extends FiltersMap>(
  filterName: string,
  filterValue: { [P in keyof F]: ExtractFilterValue<F[P]> }[string],
) => {
  const numberRangeWQLFilters = [];
  if (filterValue.from) {
    numberRangeWQLFilters.push({
      [filterName]: { $gte: filterValue.from },
    });
  }

  if (filterValue.to) {
    numberRangeWQLFilters.push({
      [filterName]: { $lte: filterValue.to },
    });
  }

  return numberRangeWQLFilters;
};
