/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { __extends, __read, __spread } from "tslib";
import { Base, typeCast, typeGetValue, markType, IComparable_$type, String_$type, Number_$type, Boolean_$type, Date_$type, getInstanceType } from "./type";
import { IFilterExpression_$type } from "./IFilterExpression";
import { Convert } from "./Convert";
import { IOperationFilterExpression_$type } from "./IOperationFilterExpression";
import { NotImplementedException } from "./NotImplementedException";
import { InvalidOperationException } from "./InvalidOperationException";
import { intDivide, isNaN_ } from "./number";
import { CompareUtil } from "./compareUtil";
import { stringCompareTo, stringConcat, stringEndsWith, stringReplace, stringStartsWith, stringContains } from "./string";
import { IFunctionFilterExpression_$type } from "./IFunctionFilterExpression";
import { FilterExpressionCollection } from "./FilterExpressionCollection";
import { DataSourceSchemaPropertyType_$type } from "./DataSourceSchemaPropertyType";
import { dateGetMonth, dateGetDate, dateNow } from "./date";
import { IPropertyReferenceFilterExpression_$type } from "./IPropertyReferenceFilterExpression";
import { ILiteralFilterExpression_$type } from "./ILiteralFilterExpression";
/**
 * @hidden
 */
var FilterExpression = /** @class */ (function (_super) {
    __extends(FilterExpression, _super);
    function FilterExpression() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.ay = false;
        _this.az = false;
        return _this;
    }
    FilterExpression.prototype.markAutoGenerated = function () {
        this.az = true;
    };
    Object.defineProperty(FilterExpression.prototype, "isAutoGenerated", {
        get: function () {
            return this.az;
        },
        enumerable: true,
        configurable: true
    });
    FilterExpression.isFilterExpression = function (a) {
        return typeCast(IFilterExpression_$type, a) !== null;
    };
    FilterExpression.operation = function (a, b, c) {
        if (FilterExpression.isFilterExpression(a)) {
            var d = a;
            if (FilterExpression.isFilterExpression(c)) {
                var e = c;
                return new OperationFilterExpression(d, b, e);
            }
            else {
                return new OperationFilterExpression(d, b, c);
            }
        }
        else {
            var f = a;
            if (FilterExpression.isFilterExpression(c)) {
                var g = c;
                return new OperationFilterExpression(f, b, g);
            }
            else {
                return new OperationFilterExpression(f, b, c);
            }
        }
    };
    FilterExpression.func = function (a) {
        var b = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            b[_i - 1] = arguments[_i];
        }
        return new (FunctionFilterExpression.bind.apply(FunctionFilterExpression, __spread([void 0, a], b)))();
    };
    FilterExpression.prototype.a4 = function () {
        this.ay = this.a2();
    };
    FilterExpression.property = function (a) {
        if (a == null) {
            return null;
        }
        var b = new PropertyReferenceFilterExpression(null);
        b.propertyReference = a;
        return b;
    };
    FilterExpression.nullLiteral = function () {
        var a = new LiteralFilterExpression(null, false);
        return a;
    };
    FilterExpression.literal = function (a) {
        var b = new LiteralFilterExpression(a, false);
        return b;
    };
    FilterExpression.unquotedLiteral = function (a) {
        var b = new LiteralFilterExpression(a, true);
        return b;
    };
    FilterExpression.prototype.match = function (a, b, c) {
        var d = this.evaluate(a, b, c);
        return this.a3(d, b, c);
    };
    FilterExpression.prototype.a3 = function (a, b, c) {
        if (!this.ay) {
            return this.a0(a, b, c);
        }
        return a;
    };
    FilterExpression.prototype.a0 = function (a, b, c) {
        return Convert.toBoolean(a);
    };
    FilterExpression.prototype.get_isPropertyReference = function () {
        return false;
    };
    Object.defineProperty(FilterExpression.prototype, "isPropertyReference", {
        get: function () {
            return this.get_isPropertyReference();
        },
        enumerable: true,
        configurable: true
    });
    FilterExpression.prototype.get_isOperation = function () {
        return false;
    };
    Object.defineProperty(FilterExpression.prototype, "isOperation", {
        get: function () {
            return this.get_isOperation();
        },
        enumerable: true,
        configurable: true
    });
    FilterExpression.prototype.get_isFunction = function () {
        return false;
    };
    Object.defineProperty(FilterExpression.prototype, "isFunction", {
        get: function () {
            return this.get_isFunction();
        },
        enumerable: true,
        configurable: true
    });
    FilterExpression.prototype.get_isLiteral = function () {
        return false;
    };
    Object.defineProperty(FilterExpression.prototype, "isLiteral", {
        get: function () {
            return this.get_isLiteral();
        },
        enumerable: true,
        configurable: true
    });
    FilterExpression.prototype.get_isNull = function () {
        return false;
    };
    Object.defineProperty(FilterExpression.prototype, "isNull", {
        get: function () {
            return this.get_isNull();
        },
        enumerable: true,
        configurable: true
    });
    FilterExpression.prototype.group = function () {
        return FilterExpression.operation(this, 15, null);
    };
    FilterExpression.prototype.and = function (a) {
        return FilterExpression.operation(this, 7, a);
    };
    FilterExpression.prototype.or = function (a) {
        return FilterExpression.operation(this, 8, a);
    };
    FilterExpression.prototype.not = function () {
        return FilterExpression.operation(this, 9, null);
    };
    FilterExpression.prototype.add = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 10, b);
        }
        else {
            return FilterExpression.operation(this, 10, a);
        }
    };
    FilterExpression.prototype.plus = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 10, b);
        }
        else {
            return FilterExpression.operation(this, 10, a);
        }
    };
    FilterExpression.prototype.divide = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 13, b);
        }
        else {
            return FilterExpression.operation(this, 13, a);
        }
    };
    FilterExpression.prototype.divideBy = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 13, b);
        }
        else {
            return FilterExpression.operation(this, 13, a);
        }
    };
    FilterExpression.prototype.isEqualTo = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 1, b);
        }
        else {
            return FilterExpression.operation(this, 1, a);
        }
    };
    FilterExpression.prototype.isGreaterThan = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 3, b);
        }
        else {
            return FilterExpression.operation(this, 3, a);
        }
    };
    FilterExpression.prototype.isGreaterThanOrEqualTo = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 4, b);
        }
        else {
            return FilterExpression.operation(this, 4, a);
        }
    };
    FilterExpression.prototype.isLessThan = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 5, b);
        }
        else {
            return FilterExpression.operation(this, 5, a);
        }
    };
    FilterExpression.prototype.isLessThanOrEqualTo = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 6, b);
        }
        else {
            return FilterExpression.operation(this, 6, a);
        }
    };
    FilterExpression.prototype.modulo = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 14, b);
        }
        else {
            return FilterExpression.operation(this, 14, a);
        }
    };
    FilterExpression.prototype.multiply = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 12, b);
        }
        else {
            return FilterExpression.operation(this, 12, a);
        }
    };
    FilterExpression.prototype.times = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 12, b);
        }
        else {
            return FilterExpression.operation(this, 12, a);
        }
    };
    FilterExpression.prototype.isNotEqualTo = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 2, b);
        }
        else {
            return FilterExpression.operation(this, 2, a);
        }
    };
    FilterExpression.prototype.subtract = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 11, b);
        }
        else {
            return FilterExpression.operation(this, 11, a);
        }
    };
    FilterExpression.prototype.minus = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.operation(this, 11, b);
        }
        else {
            return FilterExpression.operation(this, 11, a);
        }
    };
    FilterExpression.prototype.ceiling = function () {
        return FilterExpression.func(19, this);
    };
    FilterExpression.prototype.concat = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.func(10, this, b);
        }
        else {
            var c = a;
            return FilterExpression.func(10, this, FilterExpression.literal(c));
        }
    };
    FilterExpression.prototype.contains = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.func(0, this, b);
        }
        else {
            var c = a;
            return FilterExpression.func(0, this, FilterExpression.literal(c));
        }
    };
    FilterExpression.prototype.day = function () {
        return FilterExpression.func(11, this);
    };
    FilterExpression.prototype.endsWith = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.func(1, this, b);
        }
        else {
            var c = a;
            return FilterExpression.func(1, this, FilterExpression.literal(c));
        }
    };
    FilterExpression.prototype.floor = function () {
        return FilterExpression.func(18, this);
    };
    FilterExpression.prototype.hour = function () {
        return FilterExpression.func(12, this);
    };
    FilterExpression.prototype.indexOf = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.func(4, this, b);
        }
        else {
            var c = a;
            return FilterExpression.func(4, this, FilterExpression.literal(c));
        }
    };
    FilterExpression.prototype.length = function () {
        return FilterExpression.func(3, this);
    };
    FilterExpression.prototype.minute = function () {
        return FilterExpression.func(13, this);
    };
    FilterExpression.prototype.month = function () {
        return FilterExpression.func(14, this);
    };
    FilterExpression.prototype.replace = function (a, b) {
        if (FilterExpression.isFilterExpression(a)) {
            var c = a;
            if (FilterExpression.isFilterExpression(b)) {
                var d = b;
                return FilterExpression.func(5, this, c, d);
            }
            else {
                var e = b;
                return FilterExpression.func(5, this, c, FilterExpression.literal(e));
            }
        }
        else {
            var f = a;
            if (FilterExpression.isFilterExpression(b)) {
                var g = b;
                return FilterExpression.func(5, this, FilterExpression.literal(f), g);
            }
            else {
                var h = b;
                return FilterExpression.func(5, this, FilterExpression.literal(f), FilterExpression.literal(h));
            }
        }
    };
    FilterExpression.prototype.round = function () {
        return FilterExpression.func(17, this);
    };
    FilterExpression.prototype.second = function () {
        return FilterExpression.func(15, this);
    };
    FilterExpression.prototype.startsWith = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.func(2, this, b);
        }
        else {
            var c = a;
            return FilterExpression.func(2, this, FilterExpression.literal(c));
        }
    };
    FilterExpression.prototype.substring = function (a, b) {
        if (b === void 0) { b = null; }
        if (FilterExpression.isFilterExpression(a)) {
            var c = a;
            if (b == null) {
                return FilterExpression.func(6, this, c);
            }
            else {
                if (FilterExpression.isFilterExpression(b)) {
                    var d = b;
                    return FilterExpression.func(6, this, c, d);
                }
                else {
                    var e = typeGetValue(b);
                    return FilterExpression.func(6, this, c, FilterExpression.literal(e));
                }
            }
        }
        else {
            var f = typeGetValue(a);
            if (b == null) {
                return FilterExpression.func(6, this, FilterExpression.literal(f));
            }
            else {
                if (FilterExpression.isFilterExpression(b)) {
                    var g = b;
                    return FilterExpression.func(6, this, FilterExpression.literal(f), g);
                }
                else {
                    var h = typeGetValue(b);
                    return FilterExpression.func(6, this, FilterExpression.literal(f), FilterExpression.literal(h));
                }
            }
        }
    };
    FilterExpression.prototype.toLower = function () {
        return FilterExpression.func(7, this);
    };
    FilterExpression.prototype.toUpper = function () {
        return FilterExpression.func(8, this);
    };
    FilterExpression.prototype.trim = function () {
        return FilterExpression.func(9, this);
    };
    FilterExpression.prototype.year = function () {
        return FilterExpression.func(16, this);
    };
    FilterExpression.prototype.date = function () {
        return FilterExpression.func(20, this);
    };
    FilterExpression.prototype.time = function () {
        return FilterExpression.func(21, this);
    };
    FilterExpression.prototype.now = function () {
        return FilterExpression.func(22);
    };
    FilterExpression.prototype.isOf = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.func(23, this, b);
        }
        else {
            var c = a;
            return FilterExpression.func(23, this, FilterExpression.literal(a));
        }
    };
    FilterExpression.prototype.cast = function (a) {
        if (FilterExpression.isFilterExpression(a)) {
            var b = a;
            return FilterExpression.func(24, this, b);
        }
        else {
            var c = a;
            return FilterExpression.func(24, this, FilterExpression.literal(c));
        }
    };
    FilterExpression.$t = markType(FilterExpression, 'FilterExpression', Base.$, [IFilterExpression_$type]);
    return FilterExpression;
}(Base));
export { FilterExpression };
/**
 * @hidden
 */
var OperationFilterExpression = /** @class */ (function (_super) {
    __extends(OperationFilterExpression, _super);
    function OperationFilterExpression(a, b, c) {
        var _this = _super.call(this) || this;
        _this.a6 = null;
        _this.a8 = false;
        _this.a7 = null;
        _this.a9 = false;
        _this.a5 = 0;
        if (a != null) {
            if (FilterExpression.isFilterExpression(a)) {
                _this.a6 = a;
            }
            else {
                _this.propertyName = a;
            }
        }
        if (c != null) {
            if (FilterExpression.isFilterExpression(c)) {
                _this.a7 = c;
            }
            else {
                _this.value = c;
            }
        }
        _this.a5 = b;
        return _this;
    }
    OperationFilterExpression.prototype.get_isOperation = function () {
        return true;
    };
    OperationFilterExpression.prototype.a2 = function () {
        return this.bf;
    };
    Object.defineProperty(OperationFilterExpression.prototype, "isComparisonOperation", {
        get: function () {
            var a = this.operator;
            switch (a) {
                case 0:
                case 1:
                case 2:
                case 3:
                case 5:
                case 6:
                case 4: return true;
            }
            return false;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "propertyName", {
        get: function () {
            if (this.a6 == null || !this.a6.isPropertyReference) {
                return null;
            }
            return this.a6.propertyReference;
        },
        set: function (a) {
            this.left = FilterExpression.property(a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "hasPropertyName", {
        get: function () {
            return this.a6 != null && this.a6.isPropertyReference;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "value", {
        get: function () {
            if (this.a7 == null) {
                return null;
            }
            if (this.a7.isNull) {
                return null;
            }
            if (!this.a7.isLiteral) {
                return null;
            }
            return this.a7.literalValue;
        },
        set: function (a) {
            if (a == null) {
                this.right = FilterExpression.nullLiteral();
                return;
            }
            this.right = FilterExpression.literal(a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "hasValue", {
        get: function () {
            return this.a7 != null;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "left", {
        get: function () {
            return this.a6;
        },
        set: function (a) {
            this.a6 = a;
            this.a8 = true;
            this.a4();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "hasLeft", {
        get: function () {
            return this.a8;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "right", {
        get: function () {
            return this.a7;
        },
        set: function (a) {
            this.a7 = a;
            this.a9 = true;
            this.a4();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "hasRight", {
        get: function () {
            return this.a9;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "operator", {
        get: function () {
            return this.a5;
        },
        set: function (a) {
            this.a5 = a;
            this.a4();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "hasOperator", {
        get: function () {
            return this.a5 != 0;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "bf", {
        get: function () {
            switch (this.operator) {
                case 7:
                case 1:
                case 3:
                case 4:
                case 5:
                case 6:
                case 9:
                case 2:
                case 8: return true;
            }
            return false;
        },
        enumerable: true,
        configurable: true
    });
    OperationFilterExpression.prototype.get_precedence = function () {
        switch (this.operator) {
            case 15: return 0;
            case 9: return 4;
            case 12: return 6;
            case 13: return 7;
            case 14: return 8;
            case 10: return 9;
            case 11: return 10;
            case 5: return 11;
            case 3: return 12;
            case 6: return 13;
            case 4: return 14;
            case 1: return 16;
            case 2: return 17;
            case 7: return 18;
            case 8: return 19;
            case 0: return 99;
        }
        return 99;
    };
    Object.defineProperty(OperationFilterExpression.prototype, "precedence", {
        get: function () {
            return this.get_precedence();
        },
        enumerable: true,
        configurable: true
    });
    OperationFilterExpression.prototype.evaluate = function (a, b, c) {
        switch (this.operator) {
            case 10:
            case 13:
            case 14:
            case 12:
            case 11: return this.bh(a, b, c);
            case 0:
            case 1:
            case 3:
            case 4:
            case 5:
            case 6:
            case 2: return this.bi(a, b, c);
            case 7:
            case 9:
            case 8: return this.bj(a, b, c);
            case 15: if (this.left != null) {
                return this.left.evaluate(a, b, c);
            }
            else {
                if (this.right == null) {
                    return null;
                }
                return this.right.evaluate(a, b, c);
            }
        }
        throw new NotImplementedException(0);
    };
    OperationFilterExpression.prototype.bi = function (a, b, c) {
        var d = null;
        var e = null;
        var f = -1;
        if (this.left != null) {
            d = this.left.evaluate(a, b, c);
        }
        if (this.right != null) {
            e = this.right.evaluate(a, b, c);
        }
        if (d == null && e == null) {
            f = 0;
        }
        var g = null;
        var h = null;
        if (typeCast(IComparable_$type, d) !== null) {
            g = d;
        }
        if (typeCast(IComparable_$type, e) !== null) {
            h = e;
        }
        if (typeof d === 'number' && isNaN_(d) || typeof e === 'number' && isNaN_(e) || typeof d === 'number' && isNaN_(d) || typeof e === 'number' && isNaN_(e)) {
            return false;
        }
        if (g != null) {
            if (e == null) {
                f = CompareUtil.compareToObject(g, 0);
                if (f == 0) {
                    f = -1;
                }
            }
            else {
                f = CompareUtil.compareToObject(g, e);
            }
        }
        else if (h != null) {
            if (d == null) {
                var i = CompareUtil.compareToObject(h, 0);
                if (i == 0) {
                    f = 1;
                }
                else {
                    f = 1;
                    if (i == 0) {
                        f = 0;
                    }
                    if (i > 0) {
                        f = -1;
                    }
                }
            }
            else {
                var j = CompareUtil.compareToObject(h, d);
                f = 1;
                if (j == 0) {
                    f = 0;
                }
                if (j > 0) {
                    f = -1;
                }
            }
        }
        else {
            var k = null;
            var l = null;
            if (d != null) {
                k = d.toString();
            }
            if (e != null) {
                l = e.toString();
            }
            if (k != null) {
                if (l == null) {
                    f = 1;
                }
                else {
                    f = stringCompareTo(k, l);
                }
            }
            else if (l != null) {
                if (k == null) {
                    f = -1;
                }
                else {
                    var m = stringCompareTo(l, k);
                    f = 1;
                    if (m == 0) {
                        f = 0;
                    }
                    if (m > 0) {
                        f = -1;
                    }
                }
            }
            else {
                f = 0;
            }
        }
        switch (this.operator) {
            case 0:
            case 1: return f == 0;
            case 3: return f > 0;
            case 4: return f >= 0;
            case 5: return f < 0;
            case 6: return f <= 0;
            case 2: return f != 0;
        }
        throw new InvalidOperationException(0);
    };
    OperationFilterExpression.prototype.bj = function (a, b, c) {
        var d = null;
        var e = null;
        if (this.left != null) {
            d = this.left.evaluate(a, b, c);
        }
        if (this.right != null) {
            e = this.right.evaluate(a, b, c);
        }
        if (e == null && d == null) {
            return false;
        }
        if (e == null) {
            e = false;
        }
        if (d == null) {
            d = false;
        }
        switch (this.operator) {
            case 7: return d && e;
            case 9: if (this.left == null) {
                return !e;
            }
            else {
                return !d;
            }
            case 8: return d || e;
        }
        return false;
    };
    OperationFilterExpression.prototype.bh = function (a, b, c) {
        var d = null;
        var e = null;
        if (this.left != null) {
            d = this.left.evaluate(a, b, c);
        }
        if (this.right != null) {
            e = this.right.evaluate(a, b, c);
        }
        if (d == null) {
            return e;
        }
        if (e == null) {
            return d;
        }
        if (d == null && e == null) {
            return 0;
        }
        if (typeof d === 'number' || typeof e === 'number') {
            switch (this.operator) {
                case 10: return d + e;
                case 13: return d / e;
                case 14: return d % e;
                case 12: return d * e;
                case 11: return d - e;
            }
        }
        if (typeof d === 'number' || typeof e === 'number') {
            switch (this.operator) {
                case 10: return d + e;
                case 13: return d / e;
                case 14: return d % e;
                case 12: return d * e;
                case 11: return d - e;
            }
        }
        if (typeof d === 'number' || typeof e === 'number') {
            switch (this.operator) {
                case 10: return d + e;
                case 13: return d / e;
                case 14: return d % e;
                case 12: return d * e;
                case 11: return d - e;
            }
        }
        if (typeof d === 'number' || typeof e === 'number') {
            switch (this.operator) {
                case 10: return typeGetValue(d) + typeGetValue(e);
                case 13: return intDivide(typeGetValue(d), typeGetValue(e));
                case 14: return typeGetValue(d) % typeGetValue(e);
                case 12: return typeGetValue(d) * typeGetValue(e);
                case 11: return typeGetValue(d) - typeGetValue(e);
            }
        }
        if (typeof d === 'number' || typeof e === 'number') {
            switch (this.operator) {
                case 10: return typeGetValue(d) + typeGetValue(e);
                case 13: return intDivide(typeGetValue(d), typeGetValue(e));
                case 14: return typeGetValue(d) % typeGetValue(e);
                case 12: return typeGetValue(d) * typeGetValue(e);
                case 11: return typeGetValue(d) - typeGetValue(e);
            }
        }
        if (typeof d === 'number' || typeof e === 'number') {
            switch (this.operator) {
                case 10: return typeGetValue(d) + typeGetValue(e);
                case 13: return intDivide(typeGetValue(d), typeGetValue(e));
                case 14: return typeGetValue(d) % typeGetValue(e);
                case 12: return typeGetValue(d) * typeGetValue(e);
                case 11: return typeGetValue(d) - typeGetValue(e);
            }
        }
        if (typeof d === 'number' || typeof e === 'number') {
            switch (this.operator) {
                case 10: return typeGetValue(d) + typeGetValue(e);
                case 13: return intDivide(typeGetValue(d), typeGetValue(e));
                case 14: return typeGetValue(d) % typeGetValue(e);
                case 12: return typeGetValue(d) * typeGetValue(e);
                case 11: return typeGetValue(d) - typeGetValue(e);
            }
        }
        throw new NotImplementedException(0);
    };
    OperationFilterExpression.$t = markType(OperationFilterExpression, 'OperationFilterExpression', FilterExpression.$, [IOperationFilterExpression_$type]);
    return OperationFilterExpression;
}(FilterExpression));
export { OperationFilterExpression };
/**
 * @hidden
 */
var FunctionFilterExpression = /** @class */ (function (_super) {
    __extends(FunctionFilterExpression, _super);
    function FunctionFilterExpression(a) {
        var b = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            b[_i - 1] = arguments[_i];
        }
        var _this = _super.call(this) || this;
        _this.a6 = 19;
        _this.a5 = new FilterExpressionCollection();
        _this.a6 = a;
        for (var c = 0; c < b.length; c++) {
            _this.a5.add(b[c]);
        }
        return _this;
    }
    FunctionFilterExpression.prototype.get_isFunction = function () {
        return true;
    };
    FunctionFilterExpression.prototype.a2 = function () {
        return this.a7;
    };
    Object.defineProperty(FunctionFilterExpression.prototype, "functionType", {
        get: function () {
            return this.a6;
        },
        set: function (a) {
            this.a6 = a;
            this.a4();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(FunctionFilterExpression.prototype, "a7", {
        get: function () {
            switch (this.functionType) {
                case 1:
                case 2:
                case 0: return true;
            }
            return false;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(FunctionFilterExpression.prototype, "functionArguments", {
        get: function () {
            return this.a5;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(FunctionFilterExpression.prototype, "hasFunctionArguments", {
        get: function () {
            return this.a5.j.count > 0;
        },
        enumerable: true,
        configurable: true
    });
    FunctionFilterExpression.prototype.evaluate = function (a, b, c) {
        var d = null;
        var e = null;
        var f = null;
        var g = null;
        var h = this.functionArguments.j;
        if (h.count > 0) {
            for (var i = 0; i < h.count; i++) {
                var j = null;
                if (h.item(i) != null) {
                    j = h.item(i).evaluate(a, b, c);
                }
                switch (i) {
                    case 0:
                        d = j;
                        break;
                    case 1:
                        e = j;
                        break;
                    case 2:
                        f = j;
                        break;
                    case 3:
                        g = j;
                        break;
                }
                if (i > 3) {
                    break;
                }
            }
        }
        switch (this.functionType) {
            case 19:
                if (d == null) {
                    d = 0;
                }
                return Math.ceil(d);
            case 18:
                if (d == null) {
                    d = 0;
                }
                return Math.floor(d);
            case 17:
                if (d == null) {
                    d = 0;
                }
                if (typeof d === 'number') {
                    return Math.round(d);
                }
                return Math.round(d);
            case 11:
                if (d == null) {
                    return 0;
                }
                return d.getDate();
            case 12:
                if (d == null) {
                    return 0;
                }
                return d.getHours();
            case 13:
                if (d == null) {
                    return 0;
                }
                return d.getMinutes();
            case 14:
                if (d == null) {
                    return 0;
                }
                return dateGetMonth(d);
            case 16:
                if (d == null) {
                    return 0;
                }
                return d.getFullYear();
            case 15:
                if (d == null) {
                    return 0;
                }
                return d.getSeconds();
            case 20:
                if (d == null) {
                    return 0;
                }
                return dateGetDate(d);
            case 21:
                if (d == null) {
                    return 0;
                }
                return d;
            case 22: return dateNow();
            case 23:
                var k = this.ba(e, f);
                var l = d;
                if (l == null) {
                    return true;
                }
                if (k == null) {
                    return false;
                }
                if (k.isAssignableFrom(getInstanceType(l))) {
                    return true;
                }
                return false;
            case 24:
                var m = this.ba(e, f);
                var n = d;
                if (n == null) {
                    return true;
                }
                if (m == null) {
                    return false;
                }
                if (!m.isAssignableFrom(getInstanceType(n))) {
                    return null;
                }
                return this.a8(n, m);
            case 10:
                if (d == null) {
                    d = "";
                }
                if (e == null) {
                    e = "";
                }
                return stringConcat(d, e);
            case 1:
                if (d == null) {
                    d = "";
                }
                if (e == null) {
                    e = "";
                }
                return stringEndsWith(d, e);
            case 4:
                if (d == null) {
                    d = "";
                }
                if (e == null) {
                    e = "";
                }
                return d.indexOf(e);
            case 3:
                if (d == null) {
                    d = "";
                }
                return d.length;
            case 5:
                if (d == null) {
                    d = "";
                }
                if (e == null) {
                    e = "";
                }
                if (f == null) {
                    f = "";
                }
                return stringReplace(d, e, f);
            case 2:
                if (d == null) {
                    d = "";
                }
                if (e == null) {
                    e = "";
                }
                return stringStartsWith(d, e);
            case 6:
                if (d == null) {
                    d = "";
                }
                if (e == null) {
                    e = 0;
                }
                if (f != null) {
                    return d.substr(typeGetValue(e), typeGetValue(f));
                }
                else {
                    return d.substr(typeGetValue(e));
                }
            case 0:
                if (d == null) {
                    d = "";
                }
                if (e == null) {
                    e = "";
                }
                return stringContains(d, e);
            case 7:
                if (d == null) {
                    d = "";
                }
                return d.toLowerCase();
            case 8:
                if (d == null) {
                    d = "";
                }
                return d.toUpperCase();
            case 9:
                if (d == null) {
                    d = "";
                }
                return d.trim();
        }
        throw new NotImplementedException(0);
    };
    FunctionFilterExpression.prototype.get_precedence = function () {
        switch (this.functionType) {
            case 23: return 15;
            case 24: return 5;
        }
        return 2;
    };
    Object.defineProperty(FunctionFilterExpression.prototype, "precedence", {
        get: function () {
            return this.get_precedence();
        },
        enumerable: true,
        configurable: true
    });
    FunctionFilterExpression.prototype.a8 = function (a, b) {
        if (b == String_$type) {
            if (a == null) {
                return "";
            }
            return a.toString();
        }
        else if (b == Number_$type || b == Number_$type || b == Number_$type) {
            return Convert.toInt321(a);
        }
        else if (b == Boolean_$type) {
            return Convert.toBoolean(a);
        }
        else if (b == Number_$type) {
            return Convert.toByte1(a);
        }
        else if (b == Date_$type) {
            return Convert.toDateTime(a);
        }
        else if (b == Number_$type || b == Number_$type) {
            return Convert.toInt64(a);
        }
        else if (b == Number_$type) {
            return Convert.toDecimal2(a);
        }
        else {
            return a;
        }
    };
    FunctionFilterExpression.prototype.ba = function (a, b) {
        if (typeCast(DataSourceSchemaPropertyType_$type, a) !== null || typeof a === 'number') {
            var c = typeGetValue(a);
            switch (c) {
                case 2: return Boolean_$type;
                case 10: return Number_$type;
                case 9: return Date_$type;
                case 8: return Date_$type;
                case 6: return Number_$type;
                case 5: return Number_$type;
                case 1: return Number_$type;
                case 3: return Number_$type;
                case 11:
                    if (b != null && typeof b === 'string') {
                        return this.a9(b);
                    }
                    return Base.$;
                case 4: return Number_$type;
                case 7: return Number_$type;
                case 0: return String_$type;
            }
        }
        if (typeof a === 'string') {
            return this.a9(b);
        }
        return Base.$;
    };
    FunctionFilterExpression.prototype.a9 = function (a) {
        switch (a) {
            case "Edm.Boolean":
            case "Boolean":
            case "bool":
            case "boolean": return Boolean_$type;
            case "Edm.Byte":
            case "Byte":
            case "byte":
            case "Edm.SByte":
            case "SByte": return Number_$type;
            case "Edm.DateTimeOffset":
            case "DateTimeOffset": return Date_$type;
            case "Edm.DateTime":
            case "DateTime":
            case "Calendar":
            case "datetime":
            case "calendar":
            case "Edm.Time":
            case "Time":
            case "time": return Date_$type;
            case "Edm.Decimal":
            case "Decimal":
            case "decimal": return Number_$type;
            case "Edm.Double":
            case "Double":
            case "double": return Number_$type;
            case "Edm.Float":
            case "Float":
            case "float":
            case "Edm.Single":
            case "Single":
            case "single": return Number_$type;
            case "Edm.Int16":
            case "Int16":
            case "Short":
            case "short": return Number_$type;
            case "Edm.Int32":
            case "Int32":
            case "int":
            case "Integer": return Number_$type;
            case "Edm.Int64":
            case "Int64":
            case "long":
            case "Long": return Number_$type;
            case "Edm.String":
            case "String":
            case "string": return String_$type;
        }
        return Base.$;
    };
    FunctionFilterExpression.$t = markType(FunctionFilterExpression, 'FunctionFilterExpression', FilterExpression.$, [IFunctionFilterExpression_$type]);
    return FunctionFilterExpression;
}(FilterExpression));
export { FunctionFilterExpression };
/**
 * @hidden
 */
var PropertyReferenceFilterExpression = /** @class */ (function (_super) {
    __extends(PropertyReferenceFilterExpression, _super);
    function PropertyReferenceFilterExpression(a) {
        var _this = _super.call(this) || this;
        _this.a5 = null;
        _this.a5 = a;
        return _this;
    }
    PropertyReferenceFilterExpression.prototype.get_isPropertyReference = function () {
        return true;
    };
    PropertyReferenceFilterExpression.prototype.get_precedence = function () {
        return 99;
    };
    Object.defineProperty(PropertyReferenceFilterExpression.prototype, "precedence", {
        get: function () {
            return this.get_precedence();
        },
        enumerable: true,
        configurable: true
    });
    PropertyReferenceFilterExpression.prototype.a2 = function () {
        return false;
    };
    Object.defineProperty(PropertyReferenceFilterExpression.prototype, "propertyReference", {
        get: function () {
            return this.a5;
        },
        set: function (a) {
            this.a5 = a;
        },
        enumerable: true,
        configurable: true
    });
    PropertyReferenceFilterExpression.prototype.evaluate = function (a, b, c) {
        var d = b.getItemValue(a, this.propertyReference);
        return d;
    };
    PropertyReferenceFilterExpression.$t = markType(PropertyReferenceFilterExpression, 'PropertyReferenceFilterExpression', FilterExpression.$, [IPropertyReferenceFilterExpression_$type]);
    return PropertyReferenceFilterExpression;
}(FilterExpression));
export { PropertyReferenceFilterExpression };
/**
 * @hidden
 */
var LiteralFilterExpression = /** @class */ (function (_super) {
    __extends(LiteralFilterExpression, _super);
    function LiteralFilterExpression(a, b) {
        var _this = _super.call(this) || this;
        _this.a6 = null;
        _this.a5 = false;
        _this.a6 = a;
        return _this;
    }
    LiteralFilterExpression.prototype.get_precedence = function () {
        return 99;
    };
    Object.defineProperty(LiteralFilterExpression.prototype, "precedence", {
        get: function () {
            return this.get_precedence();
        },
        enumerable: true,
        configurable: true
    });
    LiteralFilterExpression.prototype.get_isLiteral = function () {
        return true;
    };
    LiteralFilterExpression.prototype.get_isNull = function () {
        return this.literalValue == null;
    };
    Object.defineProperty(LiteralFilterExpression.prototype, "literalValue", {
        get: function () {
            return this.a6;
        },
        set: function (a) {
            this.a6 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(LiteralFilterExpression.prototype, "leaveUnquoted", {
        get: function () {
            return this.a5;
        },
        set: function (a) {
            this.a5 = a;
        },
        enumerable: true,
        configurable: true
    });
    LiteralFilterExpression.prototype.a2 = function () {
        return typeCast(Boolean_$type, this.literalValue) !== null;
    };
    LiteralFilterExpression.prototype.evaluate = function (a, b, c) {
        return this.literalValue;
    };
    LiteralFilterExpression.$t = markType(LiteralFilterExpression, 'LiteralFilterExpression', FilterExpression.$, [ILiteralFilterExpression_$type]);
    return LiteralFilterExpression;
}(FilterExpression));
export { LiteralFilterExpression };
