/*
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 * as tslib_1 from "tslib";
import { IFilterExpression_$type } from "./IFilterExpression";
import { Convert } from "./Convert";
import { DataSourceSchemaPropertyType_$type } from "./DataSourceSchemaPropertyType";
import { Base, enumGetBox, markType, IComparable_$type, typeCast, typeGetValue, String_$type, Number_$type, Boolean_$type, Date_$type, getInstanceType } from "./type";
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 { dateGetMonth, dateGetDate, dateNow } from "./date";
var FilterExpression = /** @class */ (function (_super) {
    tslib_1.__extends(FilterExpression, _super);
    function FilterExpression() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.bv = false;
        return _this;
    }
    FilterExpression.operation3 = function (a, b, c) {
        return new OperationFilterExpression(4, a, b, c);
    };
    FilterExpression.operation = function (a, b, c) {
        return new OperationFilterExpression(1, a, b, c);
    };
    FilterExpression.operation2 = function (a, b, c) {
        return new OperationFilterExpression(2, a, b, c);
    };
    FilterExpression.operation1 = function (a, b, c) {
        return new OperationFilterExpression(3, a, b, c);
    };
    FilterExpression.$function = function (a) {
        var b = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            b[_i - 1] = arguments[_i];
        }
        return new (FunctionFilterExpression.bind.apply(FunctionFilterExpression, tslib_1.__spread([void 0, 1, a], b)))();
    };
    FilterExpression.prototype.bz = function () {
        this.bv = this.bx();
    };
    FilterExpression.property = function (a) {
        if (a == null) {
            return null;
        }
        var b = new PropertyReferenceFilterExpression(0);
        b.propertyReference = a;
        return b;
    };
    FilterExpression.nullLiteral = function () {
        var a = new LiteralFilterExpression(0);
        return a;
    };
    FilterExpression.literal = function (a) {
        var b = new LiteralFilterExpression(1, a);
        return b;
    };
    FilterExpression.unquotedLiteral = function (a) {
        var b = new LiteralFilterExpression(2, a, true);
        return b;
    };
    FilterExpression.prototype.match = function (a, b, c) {
        var d = this.evaluate(a, b, c);
        return this.by(d, b, c);
    };
    FilterExpression.prototype.by = function (a, b, c) {
        if (!this.bv) {
            return this.bw(a, b, c);
        }
        return a;
    };
    FilterExpression.prototype.bw = 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) {
        return FilterExpression.operation(this, 10, a);
    };
    FilterExpression.prototype.add1 = function (a) {
        return FilterExpression.operation(this, 10, FilterExpression.literal(a));
    };
    FilterExpression.prototype.plus = function (a) {
        return FilterExpression.operation(this, 10, a);
    };
    FilterExpression.prototype.plus1 = function (a) {
        return FilterExpression.operation(this, 10, FilterExpression.literal(a));
    };
    FilterExpression.prototype.divide = function (a) {
        return FilterExpression.operation(this, 13, a);
    };
    FilterExpression.prototype.divide1 = function (a) {
        return FilterExpression.operation(this, 13, FilterExpression.literal(a));
    };
    FilterExpression.prototype.dividedBy = function (a) {
        return FilterExpression.operation(this, 13, a);
    };
    FilterExpression.prototype.dividedBy1 = function (a) {
        return FilterExpression.operation(this, 13, FilterExpression.literal(a));
    };
    FilterExpression.prototype.isEqualTo = function (a) {
        return FilterExpression.operation(this, 1, a);
    };
    FilterExpression.prototype.isEqualTo1 = function (a) {
        return FilterExpression.operation(this, 1, FilterExpression.literal(a));
    };
    FilterExpression.prototype.isGreaterThan = function (a) {
        return FilterExpression.operation(this, 3, a);
    };
    FilterExpression.prototype.isGreaterThan1 = function (a) {
        return FilterExpression.operation(this, 3, FilterExpression.literal(a));
    };
    FilterExpression.prototype.isGreaterThanOrEqualTo = function (a) {
        return FilterExpression.operation(this, 4, a);
    };
    FilterExpression.prototype.isGreaterThanOrEqualTo1 = function (a) {
        return FilterExpression.operation(this, 4, FilterExpression.literal(a));
    };
    FilterExpression.prototype.isLessThan = function (a) {
        return FilterExpression.operation(this, 5, a);
    };
    FilterExpression.prototype.isLessThan1 = function (a) {
        return FilterExpression.operation(this, 5, FilterExpression.literal(a));
    };
    FilterExpression.prototype.isLessThanOrEqualTo = function (a) {
        return FilterExpression.operation(this, 6, a);
    };
    FilterExpression.prototype.isLessThanOrEqualTo1 = function (a) {
        return FilterExpression.operation(this, 6, FilterExpression.literal(a));
    };
    FilterExpression.prototype.modulo = function (a) {
        return FilterExpression.operation(this, 14, a);
    };
    FilterExpression.prototype.modulo1 = function (a) {
        return FilterExpression.operation(this, 14, FilterExpression.literal(a));
    };
    FilterExpression.prototype.multiply = function (a) {
        return FilterExpression.operation(this, 12, a);
    };
    FilterExpression.prototype.multiply1 = function (a) {
        return FilterExpression.operation(this, 12, FilterExpression.literal(a));
    };
    FilterExpression.prototype.times = function (a) {
        return FilterExpression.operation(this, 12, a);
    };
    FilterExpression.prototype.times1 = function (a) {
        return FilterExpression.operation(this, 12, FilterExpression.literal(a));
    };
    FilterExpression.prototype.isNotEqualTo = function (a) {
        return FilterExpression.operation(this, 2, a);
    };
    FilterExpression.prototype.isNotEqualTo1 = function (a) {
        return FilterExpression.operation(this, 2, FilterExpression.literal(a));
    };
    FilterExpression.prototype.subtract = function (a) {
        return FilterExpression.operation(this, 11, a);
    };
    FilterExpression.prototype.subtract1 = function (a) {
        return FilterExpression.operation(this, 11, FilterExpression.literal(a));
    };
    FilterExpression.prototype.minus = function (a) {
        return FilterExpression.operation(this, 11, a);
    };
    FilterExpression.prototype.minus1 = function (a) {
        return FilterExpression.operation(this, 11, FilterExpression.literal(a));
    };
    FilterExpression.prototype.ceiling = function () {
        return FilterExpression.$function(19, this);
    };
    FilterExpression.prototype.concat = function (a) {
        return FilterExpression.$function(10, this, a);
    };
    FilterExpression.prototype.concat1 = function (a) {
        return FilterExpression.$function(10, this, FilterExpression.literal(a));
    };
    FilterExpression.prototype.contains = function (a) {
        return FilterExpression.$function(0, this, a);
    };
    FilterExpression.prototype.contains1 = function (a) {
        return FilterExpression.$function(0, this, FilterExpression.literal(a));
    };
    FilterExpression.prototype.day = function () {
        return FilterExpression.$function(11, this);
    };
    FilterExpression.prototype.endsWith = function (a) {
        return FilterExpression.$function(1, this, a);
    };
    FilterExpression.prototype.endsWith1 = function (a) {
        return FilterExpression.$function(1, this, FilterExpression.literal(a));
    };
    FilterExpression.prototype.floor = function () {
        return FilterExpression.$function(18, this);
    };
    FilterExpression.prototype.hour = function () {
        return FilterExpression.$function(12, this);
    };
    FilterExpression.prototype.indexOf = function (a) {
        return FilterExpression.$function(4, this, a);
    };
    FilterExpression.prototype.indexOf1 = function (a) {
        return FilterExpression.$function(4, this, FilterExpression.literal(a));
    };
    FilterExpression.prototype.length = function () {
        return FilterExpression.$function(3, this);
    };
    FilterExpression.prototype.minute = function () {
        return FilterExpression.$function(13, this);
    };
    FilterExpression.prototype.month = function () {
        return FilterExpression.$function(14, this);
    };
    FilterExpression.prototype.replace = function (a, b) {
        return FilterExpression.$function(5, this, a, b);
    };
    FilterExpression.prototype.replace2 = function (a, b) {
        return FilterExpression.$function(5, this, FilterExpression.literal(a), b);
    };
    FilterExpression.prototype.replace1 = function (a, b) {
        return FilterExpression.$function(5, this, a, FilterExpression.literal(b));
    };
    FilterExpression.prototype.replace3 = function (a, b) {
        return FilterExpression.$function(5, this, FilterExpression.literal(a), FilterExpression.literal(b));
    };
    FilterExpression.prototype.round = function () {
        return FilterExpression.$function(17, this);
    };
    FilterExpression.prototype.second = function () {
        return FilterExpression.$function(15, this);
    };
    FilterExpression.prototype.startsWith = function (a) {
        return FilterExpression.$function(2, this, a);
    };
    FilterExpression.prototype.startsWith1 = function (a) {
        return FilterExpression.$function(2, this, FilterExpression.literal(a));
    };
    FilterExpression.prototype.substring = function (a) {
        return FilterExpression.$function(6, this, a);
    };
    FilterExpression.prototype.substring3 = function (a) {
        return FilterExpression.$function(6, this, FilterExpression.literal(a));
    };
    FilterExpression.prototype.substring1 = function (a, b) {
        return FilterExpression.$function(6, this, a, b);
    };
    FilterExpression.prototype.substring4 = function (a, b) {
        return FilterExpression.$function(6, this, FilterExpression.literal(a), b);
    };
    FilterExpression.prototype.substring2 = function (a, b) {
        return FilterExpression.$function(6, this, a, FilterExpression.literal(b));
    };
    FilterExpression.prototype.substring5 = function (a, b) {
        return FilterExpression.$function(6, this, FilterExpression.literal(a), FilterExpression.literal(b));
    };
    FilterExpression.prototype.toLower = function () {
        return FilterExpression.$function(7, this);
    };
    FilterExpression.prototype.toUpper = function () {
        return FilterExpression.$function(8, this);
    };
    FilterExpression.prototype.trim = function () {
        return FilterExpression.$function(9, this);
    };
    FilterExpression.prototype.year = function () {
        return FilterExpression.$function(16, this);
    };
    FilterExpression.prototype.date = function () {
        return FilterExpression.$function(20, this);
    };
    FilterExpression.prototype.time = function () {
        return FilterExpression.$function(21, this);
    };
    FilterExpression.prototype.now = function () {
        return FilterExpression.$function(22);
    };
    FilterExpression.prototype.isOf = function (a) {
        return FilterExpression.$function(23, FilterExpression.literal(enumGetBox(DataSourceSchemaPropertyType_$type, a)));
    };
    FilterExpression.prototype.cast = function (a) {
        return FilterExpression.$function(24, FilterExpression.literal(enumGetBox(DataSourceSchemaPropertyType_$type, a)));
    };
    FilterExpression.prototype.isOf1 = function (a) {
        return FilterExpression.$function(23, FilterExpression.literal(a));
    };
    FilterExpression.prototype.cast1 = function (a) {
        return FilterExpression.$function(24, FilterExpression.literal(a));
    };
    FilterExpression.$t = markType(FilterExpression, 'FilterExpression', Base.$, [IFilterExpression_$type]);
    return FilterExpression;
}(Base));
export { FilterExpression };
var OperationFilterExpression = /** @class */ (function (_super) {
    tslib_1.__extends(OperationFilterExpression, _super);
    function OperationFilterExpression(a) {
        var _rest = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            _rest[_i - 1] = arguments[_i];
        }
        var _this = _super.call(this) || this;
        _this.b2 = null;
        _this.b6 = false;
        _this.b3 = null;
        _this.b7 = false;
        _this.b0 = 0;
        a = (a == void 0) ? 0 : a;
        switch (a) {
            case 0: break;
            case 1:
                {
                    var c = _rest[0];
                    var d = _rest[1];
                    var e = _rest[2];
                    _this.b2 = c;
                    _this.b0 = d;
                    _this.b3 = e;
                }
                break;
            case 2:
                {
                    var c = _rest[0];
                    var d = _rest[1];
                    var e = _rest[2];
                    _this.propertyName = c;
                    _this.b0 = d;
                    _this.b3 = e;
                }
                break;
            case 3:
                {
                    var c = _rest[0];
                    var d = _rest[1];
                    var e = _rest[2];
                    _this.b2 = c;
                    _this.b0 = d;
                    _this.value = e;
                }
                break;
            case 4:
                {
                    var c = _rest[0];
                    var d = _rest[1];
                    var e = _rest[2];
                    _this.propertyName = c;
                    _this.b0 = d;
                    _this.value = e;
                }
                break;
        }
        return _this;
    }
    OperationFilterExpression.prototype.get_isOperation = function () {
        return true;
    };
    Object.defineProperty(OperationFilterExpression.prototype, "isOperation", {
        get: function () {
            return this.get_isOperation();
        },
        enumerable: true,
        configurable: true
    });
    OperationFilterExpression.prototype.bx = function () {
        return this.cd;
    };
    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.b2 == null || !this.b2.isPropertyReference) {
                return null;
            }
            return this.b2.propertyReference;
        },
        set: function (a) {
            this.left = FilterExpression.property(a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "hasPropertyName", {
        get: function () {
            return this.b2 != null && this.b2.isPropertyReference;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "value", {
        get: function () {
            if (this.b3 == null) {
                return null;
            }
            if (this.b3.isNull) {
                return null;
            }
            if (!this.b3.isLiteral) {
                return null;
            }
            return this.b3.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.b3 != null;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "left", {
        get: function () {
            return this.b2;
        },
        set: function (a) {
            this.b2 = a;
            this.b6 = true;
            this.bz();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "hasLeft", {
        get: function () {
            return this.b6;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "right", {
        get: function () {
            return this.b3;
        },
        set: function (a) {
            this.b3 = a;
            this.b7 = true;
            this.bz();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "hasRight", {
        get: function () {
            return this.b7;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "operator", {
        get: function () {
            return this.b0;
        },
        set: function (a) {
            this.b0 = a;
            this.bz();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "hasOperator", {
        get: function () {
            return this.b0 != 0;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OperationFilterExpression.prototype, "cd", {
        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.evaluate = function (a, b, c) {
        switch (this.operator) {
            case 10:
            case 13:
            case 14:
            case 12:
            case 11: return this.cf(a, b, c);
            case 0:
            case 1:
            case 3:
            case 4:
            case 5:
            case 6:
            case 2: return this.cg(a, b, c);
            case 7:
            case 9:
            case 8: return this.ch(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.cg = 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.ch = 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.cf = 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.$);
    return OperationFilterExpression;
}(FilterExpression));
export { OperationFilterExpression };
var FunctionFilterExpression = /** @class */ (function (_super) {
    tslib_1.__extends(FunctionFilterExpression, _super);
    function FunctionFilterExpression(a) {
        var _rest = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            _rest[_i - 1] = arguments[_i];
        }
        var _this = _super.call(this) || this;
        _this.b1 = 19;
        _this.b0 = new FilterExpressionCollection();
        a = (a == void 0) ? 0 : a;
        switch (a) {
            case 0: break;
            case 1:
                {
                    var c = _rest[0];
                    var d = [];
                    for (var b = 1; b < _rest.length; b++) {
                        d[b - 1] = _rest[b];
                    }
                    _this.b1 = c;
                    for (var e = 0; e < d.length; e++) {
                        _this.b0.g(d[e]);
                    }
                }
                break;
        }
        return _this;
    }
    FunctionFilterExpression.prototype.get_isFunction = function () {
        return true;
    };
    Object.defineProperty(FunctionFilterExpression.prototype, "isFunction", {
        get: function () {
            return this.get_isFunction();
        },
        enumerable: true,
        configurable: true
    });
    FunctionFilterExpression.prototype.bx = function () {
        return this.b2;
    };
    Object.defineProperty(FunctionFilterExpression.prototype, "functionType", {
        get: function () {
            return this.b1;
        },
        set: function (a) {
            this.b1 = a;
            this.bz();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(FunctionFilterExpression.prototype, "b2", {
        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.b0;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(FunctionFilterExpression.prototype, "hasFunctionArguments", {
        get: function () {
            return this.b0.i.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.i;
        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.b5(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.b5(e, f);
                var n = d;
                if (n == null) {
                    return true;
                }
                if (m == null) {
                    return false;
                }
                if (!m.isAssignableFrom(getInstanceType(n))) {
                    return null;
                }
                return this.b3(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.b3 = 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.b5 = 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.b4(b);
                    }
                    return Base.$;
                case 4: return Number_$type;
                case 7: return Number_$type;
                case 0: return String_$type;
            }
        }
        if (typeof a === 'string') {
            return this.b4(b);
        }
        return Base.$;
    };
    FunctionFilterExpression.prototype.b4 = 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 };
var PropertyReferenceFilterExpression = /** @class */ (function (_super) {
    tslib_1.__extends(PropertyReferenceFilterExpression, _super);
    function PropertyReferenceFilterExpression(a) {
        var _rest = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            _rest[_i - 1] = arguments[_i];
        }
        var _this = _super.call(this) || this;
        _this.b0 = null;
        a = (a == void 0) ? 0 : a;
        switch (a) {
            case 0: break;
            case 1:
                {
                    var c = _rest[0];
                    _this.b0 = c;
                }
                break;
        }
        return _this;
    }
    PropertyReferenceFilterExpression.prototype.get_isPropertyReference = function () {
        return true;
    };
    Object.defineProperty(PropertyReferenceFilterExpression.prototype, "isPropertyReference", {
        get: function () {
            return this.get_isPropertyReference();
        },
        enumerable: true,
        configurable: true
    });
    PropertyReferenceFilterExpression.prototype.bx = function () {
        return false;
    };
    Object.defineProperty(PropertyReferenceFilterExpression.prototype, "propertyReference", {
        get: function () {
            return this.b0;
        },
        set: function (a) {
            this.b0 = 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.$);
    return PropertyReferenceFilterExpression;
}(FilterExpression));
export { PropertyReferenceFilterExpression };
var LiteralFilterExpression = /** @class */ (function (_super) {
    tslib_1.__extends(LiteralFilterExpression, _super);
    function LiteralFilterExpression(a) {
        var _rest = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            _rest[_i - 1] = arguments[_i];
        }
        var _this = _super.call(this) || this;
        _this.b2 = null;
        _this.b0 = false;
        a = (a == void 0) ? 0 : a;
        switch (a) {
            case 0: break;
            case 1:
                {
                    var c = _rest[0];
                    _this.b2 = c;
                }
                break;
            case 2:
                {
                    var c = _rest[0];
                    var d = _rest[1];
                    _this.b2 = c;
                    _this.b0 = d;
                }
                break;
        }
        return _this;
    }
    LiteralFilterExpression.prototype.get_isLiteral = function () {
        return true;
    };
    Object.defineProperty(LiteralFilterExpression.prototype, "isLiteral", {
        get: function () {
            return this.get_isLiteral();
        },
        enumerable: true,
        configurable: true
    });
    LiteralFilterExpression.prototype.get_isNull = function () {
        return this.literalValue == null;
    };
    Object.defineProperty(LiteralFilterExpression.prototype, "isNull", {
        get: function () {
            return this.get_isNull();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(LiteralFilterExpression.prototype, "literalValue", {
        get: function () {
            return this.b2;
        },
        set: function (a) {
            this.b2 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(LiteralFilterExpression.prototype, "leaveUnquoted", {
        get: function () {
            return this.b0;
        },
        set: function (a) {
            this.b0 = a;
        },
        enumerable: true,
        configurable: true
    });
    LiteralFilterExpression.prototype.bx = function () {
        return typeCast(Boolean_$type, this.literalValue) !== null;
    };
    LiteralFilterExpression.prototype.evaluate = function (a, b, c) {
        return this.literalValue;
    };
    LiteralFilterExpression.$t = markType(LiteralFilterExpression, 'LiteralFilterExpression', FilterExpression.$);
    return LiteralFilterExpression;
}(FilterExpression));
export { LiteralFilterExpression };
//# sourceMappingURL=FilterExpression_combined.js.map