/*
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 { 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
 */
export class FilterExpression extends Base {
    constructor() {
        super(...arguments);
        this.ay = false;
        this.az = false;
    }
    markAutoGenerated() {
        this.az = true;
    }
    get isAutoGenerated() {
        return this.az;
    }
    static isFilterExpression(a) {
        return typeCast(IFilterExpression_$type, a) !== null;
    }
    static operation(a, b, c) {
        if (FilterExpression.isFilterExpression(a)) {
            let d = a;
            if (FilterExpression.isFilterExpression(c)) {
                let e = c;
                return new OperationFilterExpression(d, b, e);
            }
            else {
                return new OperationFilterExpression(d, b, c);
            }
        }
        else {
            let f = a;
            if (FilterExpression.isFilterExpression(c)) {
                let g = c;
                return new OperationFilterExpression(f, b, g);
            }
            else {
                return new OperationFilterExpression(f, b, c);
            }
        }
    }
    static func(a, ...b) {
        return new FunctionFilterExpression(a, ...b);
    }
    a4() {
        this.ay = this.a2();
    }
    static property(a) {
        if (a == null) {
            return null;
        }
        let b = new PropertyReferenceFilterExpression(null);
        b.propertyReference = a;
        return b;
    }
    static nullLiteral() {
        let a = new LiteralFilterExpression(null, false);
        return a;
    }
    static literal(a) {
        let b = new LiteralFilterExpression(a, false);
        return b;
    }
    static unquotedLiteral(a) {
        let b = new LiteralFilterExpression(a, true);
        return b;
    }
    match(a, b, c) {
        let d = this.evaluate(a, b, c);
        return this.a3(d, b, c);
    }
    a3(a, b, c) {
        if (!this.ay) {
            return this.a0(a, b, c);
        }
        return a;
    }
    a0(a, b, c) {
        return Convert.toBoolean(a);
    }
    get_isPropertyReference() {
        return false;
    }
    get isPropertyReference() {
        return this.get_isPropertyReference();
    }
    get_isOperation() {
        return false;
    }
    get isOperation() {
        return this.get_isOperation();
    }
    get_isFunction() {
        return false;
    }
    get isFunction() {
        return this.get_isFunction();
    }
    get_isLiteral() {
        return false;
    }
    get isLiteral() {
        return this.get_isLiteral();
    }
    get_isNull() {
        return false;
    }
    get isNull() {
        return this.get_isNull();
    }
    group() {
        return FilterExpression.operation(this, 15, null);
    }
    and(a) {
        return FilterExpression.operation(this, 7, a);
    }
    or(a) {
        return FilterExpression.operation(this, 8, a);
    }
    not() {
        return FilterExpression.operation(this, 9, null);
    }
    add(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 10, b);
        }
        else {
            return FilterExpression.operation(this, 10, a);
        }
    }
    plus(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 10, b);
        }
        else {
            return FilterExpression.operation(this, 10, a);
        }
    }
    divide(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 13, b);
        }
        else {
            return FilterExpression.operation(this, 13, a);
        }
    }
    divideBy(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 13, b);
        }
        else {
            return FilterExpression.operation(this, 13, a);
        }
    }
    isEqualTo(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 1, b);
        }
        else {
            return FilterExpression.operation(this, 1, a);
        }
    }
    isGreaterThan(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 3, b);
        }
        else {
            return FilterExpression.operation(this, 3, a);
        }
    }
    isGreaterThanOrEqualTo(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 4, b);
        }
        else {
            return FilterExpression.operation(this, 4, a);
        }
    }
    isLessThan(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 5, b);
        }
        else {
            return FilterExpression.operation(this, 5, a);
        }
    }
    isLessThanOrEqualTo(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 6, b);
        }
        else {
            return FilterExpression.operation(this, 6, a);
        }
    }
    modulo(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 14, b);
        }
        else {
            return FilterExpression.operation(this, 14, a);
        }
    }
    multiply(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 12, b);
        }
        else {
            return FilterExpression.operation(this, 12, a);
        }
    }
    times(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 12, b);
        }
        else {
            return FilterExpression.operation(this, 12, a);
        }
    }
    isNotEqualTo(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 2, b);
        }
        else {
            return FilterExpression.operation(this, 2, a);
        }
    }
    subtract(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 11, b);
        }
        else {
            return FilterExpression.operation(this, 11, a);
        }
    }
    minus(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.operation(this, 11, b);
        }
        else {
            return FilterExpression.operation(this, 11, a);
        }
    }
    ceiling() {
        return FilterExpression.func(19, this);
    }
    concat(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.func(10, this, b);
        }
        else {
            let c = a;
            return FilterExpression.func(10, this, FilterExpression.literal(c));
        }
    }
    contains(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.func(0, this, b);
        }
        else {
            let c = a;
            return FilterExpression.func(0, this, FilterExpression.literal(c));
        }
    }
    day() {
        return FilterExpression.func(11, this);
    }
    endsWith(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.func(1, this, b);
        }
        else {
            let c = a;
            return FilterExpression.func(1, this, FilterExpression.literal(c));
        }
    }
    floor() {
        return FilterExpression.func(18, this);
    }
    hour() {
        return FilterExpression.func(12, this);
    }
    indexOf(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.func(4, this, b);
        }
        else {
            let c = a;
            return FilterExpression.func(4, this, FilterExpression.literal(c));
        }
    }
    length() {
        return FilterExpression.func(3, this);
    }
    minute() {
        return FilterExpression.func(13, this);
    }
    month() {
        return FilterExpression.func(14, this);
    }
    replace(a, b) {
        if (FilterExpression.isFilterExpression(a)) {
            let c = a;
            if (FilterExpression.isFilterExpression(b)) {
                let d = b;
                return FilterExpression.func(5, this, c, d);
            }
            else {
                let e = b;
                return FilterExpression.func(5, this, c, FilterExpression.literal(e));
            }
        }
        else {
            let f = a;
            if (FilterExpression.isFilterExpression(b)) {
                let g = b;
                return FilterExpression.func(5, this, FilterExpression.literal(f), g);
            }
            else {
                let h = b;
                return FilterExpression.func(5, this, FilterExpression.literal(f), FilterExpression.literal(h));
            }
        }
    }
    round() {
        return FilterExpression.func(17, this);
    }
    second() {
        return FilterExpression.func(15, this);
    }
    startsWith(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.func(2, this, b);
        }
        else {
            let c = a;
            return FilterExpression.func(2, this, FilterExpression.literal(c));
        }
    }
    substring(a, b = null) {
        if (FilterExpression.isFilterExpression(a)) {
            let c = a;
            if (b == null) {
                return FilterExpression.func(6, this, c);
            }
            else {
                if (FilterExpression.isFilterExpression(b)) {
                    let d = b;
                    return FilterExpression.func(6, this, c, d);
                }
                else {
                    let e = typeGetValue(b);
                    return FilterExpression.func(6, this, c, FilterExpression.literal(e));
                }
            }
        }
        else {
            let f = typeGetValue(a);
            if (b == null) {
                return FilterExpression.func(6, this, FilterExpression.literal(f));
            }
            else {
                if (FilterExpression.isFilterExpression(b)) {
                    let g = b;
                    return FilterExpression.func(6, this, FilterExpression.literal(f), g);
                }
                else {
                    let h = typeGetValue(b);
                    return FilterExpression.func(6, this, FilterExpression.literal(f), FilterExpression.literal(h));
                }
            }
        }
    }
    toLower() {
        return FilterExpression.func(7, this);
    }
    toUpper() {
        return FilterExpression.func(8, this);
    }
    trim() {
        return FilterExpression.func(9, this);
    }
    year() {
        return FilterExpression.func(16, this);
    }
    date() {
        return FilterExpression.func(20, this);
    }
    time() {
        return FilterExpression.func(21, this);
    }
    now() {
        return FilterExpression.func(22);
    }
    isOf(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.func(23, this, b);
        }
        else {
            let c = a;
            return FilterExpression.func(23, this, FilterExpression.literal(a));
        }
    }
    cast(a) {
        if (FilterExpression.isFilterExpression(a)) {
            let b = a;
            return FilterExpression.func(24, this, b);
        }
        else {
            let c = a;
            return FilterExpression.func(24, this, FilterExpression.literal(c));
        }
    }
}
FilterExpression.$t = markType(FilterExpression, 'FilterExpression', Base.$, [IFilterExpression_$type]);
/**
 * @hidden
 */
export class OperationFilterExpression extends FilterExpression {
    constructor(a, b, c) {
        super();
        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;
    }
    get_isOperation() {
        return true;
    }
    a2() {
        return this.bf;
    }
    get isComparisonOperation() {
        let a = this.operator;
        switch (a) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 5:
            case 6:
            case 4: return true;
        }
        return false;
    }
    get propertyName() {
        if (this.a6 == null || !this.a6.isPropertyReference) {
            return null;
        }
        return this.a6.propertyReference;
    }
    set propertyName(a) {
        this.left = FilterExpression.property(a);
    }
    get hasPropertyName() {
        return this.a6 != null && this.a6.isPropertyReference;
    }
    get value() {
        if (this.a7 == null) {
            return null;
        }
        if (this.a7.isNull) {
            return null;
        }
        if (!this.a7.isLiteral) {
            return null;
        }
        return this.a7.literalValue;
    }
    set value(a) {
        if (a == null) {
            this.right = FilterExpression.nullLiteral();
            return;
        }
        this.right = FilterExpression.literal(a);
    }
    get hasValue() {
        return this.a7 != null;
    }
    get left() {
        return this.a6;
    }
    set left(a) {
        this.a6 = a;
        this.a8 = true;
        this.a4();
    }
    get hasLeft() {
        return this.a8;
    }
    get right() {
        return this.a7;
    }
    set right(a) {
        this.a7 = a;
        this.a9 = true;
        this.a4();
    }
    get hasRight() {
        return this.a9;
    }
    get operator() {
        return this.a5;
    }
    set operator(a) {
        this.a5 = a;
        this.a4();
    }
    get hasOperator() {
        return this.a5 != 0;
    }
    get bf() {
        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;
    }
    get_precedence() {
        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;
    }
    get precedence() {
        return this.get_precedence();
    }
    evaluate(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);
    }
    bi(a, b, c) {
        let d = null;
        let e = null;
        let 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;
        }
        let g = null;
        let 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) {
                let i = CompareUtil.compareToObject(h, 0);
                if (i == 0) {
                    f = 1;
                }
                else {
                    f = 1;
                    if (i == 0) {
                        f = 0;
                    }
                    if (i > 0) {
                        f = -1;
                    }
                }
            }
            else {
                let j = CompareUtil.compareToObject(h, d);
                f = 1;
                if (j == 0) {
                    f = 0;
                }
                if (j > 0) {
                    f = -1;
                }
            }
        }
        else {
            let k = null;
            let 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 {
                    let 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);
    }
    bj(a, b, c) {
        let d = null;
        let 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;
    }
    bh(a, b, c) {
        let d = null;
        let 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]);
/**
 * @hidden
 */
export class FunctionFilterExpression extends FilterExpression {
    constructor(a, ...b) {
        super();
        this.a6 = 19;
        this.a5 = new FilterExpressionCollection();
        this.a6 = a;
        for (let c = 0; c < b.length; c++) {
            this.a5.add(b[c]);
        }
    }
    get_isFunction() {
        return true;
    }
    a2() {
        return this.a7;
    }
    get functionType() {
        return this.a6;
    }
    set functionType(a) {
        this.a6 = a;
        this.a4();
    }
    get a7() {
        switch (this.functionType) {
            case 1:
            case 2:
            case 0: return true;
        }
        return false;
    }
    get functionArguments() {
        return this.a5;
    }
    get hasFunctionArguments() {
        return this.a5.j.count > 0;
    }
    evaluate(a, b, c) {
        let d = null;
        let e = null;
        let f = null;
        let g = null;
        let h = this.functionArguments.j;
        if (h.count > 0) {
            for (let i = 0; i < h.count; i++) {
                let 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:
                let k = this.ba(e, f);
                let l = d;
                if (l == null) {
                    return true;
                }
                if (k == null) {
                    return false;
                }
                if (k.isAssignableFrom(getInstanceType(l))) {
                    return true;
                }
                return false;
            case 24:
                let m = this.ba(e, f);
                let 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);
    }
    get_precedence() {
        switch (this.functionType) {
            case 23: return 15;
            case 24: return 5;
        }
        return 2;
    }
    get precedence() {
        return this.get_precedence();
    }
    a8(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;
        }
    }
    ba(a, b) {
        if (typeCast(DataSourceSchemaPropertyType_$type, a) !== null || typeof a === 'number') {
            let 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.$;
    }
    a9(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]);
/**
 * @hidden
 */
export class PropertyReferenceFilterExpression extends FilterExpression {
    constructor(a) {
        super();
        this.a5 = null;
        this.a5 = a;
    }
    get_isPropertyReference() {
        return true;
    }
    get_precedence() {
        return 99;
    }
    get precedence() {
        return this.get_precedence();
    }
    a2() {
        return false;
    }
    get propertyReference() {
        return this.a5;
    }
    set propertyReference(a) {
        this.a5 = a;
    }
    evaluate(a, b, c) {
        let d = b.getItemValue(a, this.propertyReference);
        return d;
    }
}
PropertyReferenceFilterExpression.$t = markType(PropertyReferenceFilterExpression, 'PropertyReferenceFilterExpression', FilterExpression.$, [IPropertyReferenceFilterExpression_$type]);
/**
 * @hidden
 */
export class LiteralFilterExpression extends FilterExpression {
    constructor(a, b) {
        super();
        this.a6 = null;
        this.a5 = false;
        this.a6 = a;
    }
    get_precedence() {
        return 99;
    }
    get precedence() {
        return this.get_precedence();
    }
    get_isLiteral() {
        return true;
    }
    get_isNull() {
        return this.literalValue == null;
    }
    get literalValue() {
        return this.a6;
    }
    set literalValue(a) {
        this.a6 = a;
    }
    get leaveUnquoted() {
        return this.a5;
    }
    set leaveUnquoted(a) {
        this.a5 = a;
    }
    a2() {
        return typeCast(Boolean_$type, this.literalValue) !== null;
    }
    evaluate(a, b, c) {
        return this.literalValue;
    }
}
LiteralFilterExpression.$t = markType(LiteralFilterExpression, 'LiteralFilterExpression', FilterExpression.$, [ILiteralFilterExpression_$type]);
