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

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

  if (filterValue.to instanceof Date) {
    dateWQLFilters.push({
      [filterName]: { $lte: filterValue.to.toISOString() },
    });
  }

  return dateWQLFilters;
};
