"use strict";

exports.__esModule = true;
exports.transformOperatorFilterToWQL = void 0;
var _bexCore = require("@wix/bex-core");
/**
 * Transform an operator filter value to WQL (Wix Query Language) format
 * @param filterName - The name of the field being filtered
 * @param filterValue - The operator filter value containing operator and value
 * @returns Array of WQL filter objects, or empty array if filter should not be applied
 */
const transformOperatorFilterToWQL = (filterName, filterValue) => {
  if (!filterValue) {
    return [];
  }
  const {
    operator,
    value
  } = filterValue;
  if (operator === _bexCore.FilterOperator.IS_EMPTY) {
    return [{
      [filterName]: {
        $eq: null
      }
    }];
  }
  if (operator === _bexCore.FilterOperator.EXISTS) {
    return [{
      [filterName]: {
        $exists: true
      }
    }];
  }
  if (value === null || value === undefined || value === '') {
    return [];
  }
  switch (operator) {
    case _bexCore.FilterOperator.EQUALS:
      return [{
        [filterName]: {
          $eq: value
        }
      }];
    case _bexCore.FilterOperator.NOT_EQUALS:
      return [{
        $not: {
          [filterName]: {
            $eq: value
          }
        }
      }];
    case _bexCore.FilterOperator.IN:
      return [{
        [filterName]: {
          $in: Array.isArray(value) ? value : [value]
        }
      }];
    case _bexCore.FilterOperator.NOT_IN:
      return [{
        [filterName]: {
          $nin: Array.isArray(value) ? value : [value]
        }
      }];
    case _bexCore.FilterOperator.STARTS_WITH:
      return [{
        [filterName]: {
          $startsWith: value
        }
      }];
    case _bexCore.FilterOperator.CONTAINS:
      return [{
        [filterName]: {
          $contains: value
        }
      }];
    case _bexCore.FilterOperator.NOT_CONTAINS:
      return [{
        $not: {
          [filterName]: {
            $contains: value
          }
        }
      }];
    case _bexCore.FilterOperator.LESS_THAN:
      return [{
        [filterName]: {
          $lt: value
        }
      }];
    case _bexCore.FilterOperator.LESS_THAN_OR_EQUAL:
      return [{
        [filterName]: {
          $lte: value
        }
      }];
    case _bexCore.FilterOperator.GREATER_THAN:
      return [{
        [filterName]: {
          $gt: value
        }
      }];
    case _bexCore.FilterOperator.GREATER_THAN_OR_EQUAL:
      return [{
        [filterName]: {
          $gte: value
        }
      }];
    default:
      return [];
  }
};
exports.transformOperatorFilterToWQL = transformOperatorFilterToWQL;
//# sourceMappingURL=transformOperatorFilterToWQL.js.map