"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var QueryCriteria = exports.QueryCriteria = function () {
    function QueryCriteria() {
        _classCallCheck(this, QueryCriteria);
    }

    _createClass(QueryCriteria, [{
        key: "like",
        value: function like(field, value) {
            return function (item) {
                return item[field].includes(value);
            };
        }
    }, {
        key: "eq",
        value: function eq(field, value) {
            return function (item) {
                return item[field] === value;
            };
        }
    }, {
        key: "neq",
        value: function neq(field, value) {
            return function (item) {
                return item[field] !== value;
            };
        }
    }, {
        key: "lt",
        value: function lt(field, value) {
            return function (item) {
                return item[field] < value;
            };
        }
    }, {
        key: "lte",
        value: function lte(field, value) {
            return function (item) {
                return item[field] <= value;
            };
        }
    }, {
        key: "gt",
        value: function gt(field, value) {
            return function (item) {
                return item[field] > value;
            };
        }
    }, {
        key: "gte",
        value: function gte(field, value) {
            return function (item) {
                return item[field] >= value;
            };
        }
    }, {
        key: "in",
        value: function _in(field, value) {
            return function (item) {
                return value.includes(item[field]);
            };
        }
    }, {
        key: "notin",
        value: function notin(field, value) {
            return function (item) {
                return !value.includes(item[field]);
            };
        }
    }, {
        key: "andX",
        value: function andX() {
            var _this = this,
                _arguments = arguments;

            return function (item) {
                var response = true;
                _this.extractFunctions(_arguments).forEach(function (filter) {
                    if (!response) return;

                    response = filter(item);
                });

                return response;
            };
        }
    }, {
        key: "orX",
        value: function orX() {
            var _this2 = this,
                _arguments2 = arguments;

            return function (item) {
                var response = false;
                _this2.extractFunctions(_arguments2).forEach(function (filter) {
                    if (response) return;

                    response = filter(item);
                });

                return response;
            };
        }
    }, {
        key: "extractFunctions",
        value: function extractFunctions(filters) {
            return Object.keys(filters).map(function (key) {
                return filters[key];
            });
        }
    }]);

    return QueryCriteria;
}();