"use strict";

var __assign = void 0 && (void 0).__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  return mod && mod.__esModule ? mod : {
    "default": mod
  };
};

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.formatFilterData = exports.translateFilterData = exports.getDurationOfFastType = void 0;

var constant_1 = require("./constant");

var dayjs_1 = __importDefault(require("dayjs"));

var constant_2 = require("./constant");

var getDurationOfFastType = function getDurationOfFastType(fast, val, type, unit, fastMap) {
  if (!fast) return [null, null];

  if (fast === constant_1.FastTypeKeys.customer) {
    if (type === constant_1.DynamincType.after) {
      return [dayjs_1["default"](), dayjs_1["default"]().add(val || 0, unit)];
    }

    return [dayjs_1["default"]().subtract(val || 0, unit), dayjs_1["default"]()];
  }

  return fastMap[fast];
};

exports.getDurationOfFastType = getDurationOfFastType;
/** 翻译传进来的结构 */

var translateFilterData = function translateFilterData(data) {
  var $and = data.$and;
  var result = [];
  $and.forEach(function (andArr) {
    var notTrans = andArr.$or.map(function (orObj) {
      var obj;

      if (orObj.$not) {
        var _a = orObj.$not,
            type = _a.type,
            value = _a.value;

        if (type === constant_2.FilterTypeKeys.empty) {
          obj = {
            value: value,
            type: constant_2.FilterTypeKeys.unempty
          };
        }

        if (type === constant_2.FilterTypeKeys.contain) {
          obj = {
            value: value,
            type: constant_2.FilterTypeKeys.nocontain
          };
        }
      } else {
        obj = orObj;
      }

      return obj;
    });
    result.push(notTrans);
  });
  return result;
};

exports.translateFilterData = translateFilterData;
/** 规范传出结构 */

var formatFilterData = function formatFilterData(data) {
  var andResult = data.map(function (orArr) {
    var orObj = {
      $or: {}
    };
    orObj.$or = orArr.map(function (obj) {
      var box = obj;

      if (obj.type === constant_2.FilterTypeKeys.unempty) {
        box = {
          $not: __assign(__assign({}, obj), {
            type: constant_2.FilterTypeKeys.empty
          })
        };
      }

      if (obj.type === constant_2.FilterTypeKeys.nocontain) {
        box = {
          $not: __assign(__assign({}, obj), {
            type: constant_2.FilterTypeKeys.contain
          })
        };
      }

      return box;
    });
    return orObj;
  });
  return {
    $and: andResult
  };
};

exports.formatFilterData = formatFilterData;

