/*
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 { ISupportsDataChangeNotifications_$type } from "./ISupportsDataChangeNotifications";
import { IDataSourceSupportsCount_$type } from "./IDataSourceSupportsCount";
import { Base, Type, markType, typeGetValue } from "./type";
import { SyncableObservableCollection$1 } from "./SyncableObservableCollection$1";
import { IDataSourceSupportsIndexedAccess_$type } from "./IDataSourceSupportsIndexedAccess";
import { DefaultSummaryResult } from "./DefaultSummaryResult";
import { stringCompare } from "./string";
/**
 * @hidden
 */
export let IDataSourceDataProvider_$type = new Type(null, 'IDataSourceDataProvider', null, [ISupportsDataChangeNotifications_$type, IDataSourceSupportsCount_$type]);
/**
 * @hidden
 */
export let IFilterExpression_$type = new Type(null, 'IFilterExpression');
/**
 * @hidden
 */
export class FilterExpressionCollection extends Base {
    constructor() {
        super();
        this.a = null;
        this.f = null;
        this.f = new SyncableObservableCollection$1(IFilterExpression_$type);
    }
    get syncTarget() {
        return this.a;
    }
    set syncTarget(a) {
        if (a == null) {
            this.f.syncTarget = null;
            this.a = null;
            return;
        }
        this.a = a;
        this.f.syncTarget = this.a.f;
    }
    add(a) {
        return this.f.add(a);
    }
    insert(a, b) {
        this.f.add1(a, b);
    }
    clear() {
        this.f.clear();
    }
    get(a) {
        return this.f.get(a);
    }
    indexOf(a) {
        return this.f.indexOf(a);
    }
    remove(a) {
        return this.f.remove1(a);
    }
    removeAt(a) {
        return this.f.remove(a);
    }
    set(a, b) {
        return this.f.set(a, b);
    }
    size() {
        return this.f.size();
    }
    get onChanged() {
        return this.f.f;
    }
    set onChanged(a) {
        this.f.f = a;
    }
    m(a) {
        this.f.addListener(a);
    }
    p(a) {
        this.f.removeListener(a);
    }
    get j() {
        return this.f.all;
    }
}
FilterExpressionCollection.$t = markType(FilterExpressionCollection, 'FilterExpressionCollection');
/**
 * @hidden
 */
export let IDataSource_$type = new Type(null, 'IDataSource', null, [ISupportsDataChangeNotifications_$type, IDataSourceSupportsIndexedAccess_$type]);
/**
 * @hidden
 */
export class SummaryCalculator extends Base {
    constructor() {
        super(...arguments);
        this.j = null;
        this.a = 0;
        this.b = null;
        this.i = null;
        this.g = false;
    }
    l(a, b) {
        this.b = a;
        this.j = b;
        if (this.j != null) {
            this.a = a.resolveSchemaPropertyType(this.j);
        }
        this.g = false;
    }
    c() {
        return null;
    }
    k(a) {
    }
    d(a, b, c) {
        return b;
    }
    f(a, b, c) {
        return b;
    }
    e(a, b, c, d) {
        return c;
    }
    h(a) {
        let b = this.b.getItemProperty(a, this.j);
        switch (this.a) {
            case 6: return b;
            case 5: return b;
            case 1: return typeGetValue(b);
            case 3: return typeGetValue(b);
            case 4: return typeGetValue(b);
            case 7: return b;
        }
        return 0;
    }
}
SummaryCalculator.$t = markType(SummaryCalculator, 'SummaryCalculator');
/**
 * @hidden
 */
export class SumSummaryCalculator extends SummaryCalculator {
    constructor() {
        super(...arguments);
        this.m = 0;
    }
    get_i() {
        return "Sum";
    }
    l(a, b) {
        super.l(a, b);
        this.m = 0;
    }
    c() {
        return new DefaultSummaryResult(this.j, 2, this.m);
    }
    k(a) {
        this.m += this.h(a);
    }
    d(a, b, c) {
        let d = b.value + this.h(a);
        return new DefaultSummaryResult(this.j, 2, d);
    }
    f(a, b, c) {
        let d = b.value - this.h(a);
        return new DefaultSummaryResult(this.j, 2, d);
    }
    e(a, b, c, d) {
        let e = c.value - this.h(b) + this.h(a);
        return new DefaultSummaryResult(this.j, 2, e);
    }
}
SumSummaryCalculator.$t = markType(SumSummaryCalculator, 'SumSummaryCalculator', SummaryCalculator.$);
/**
 * @hidden
 */
export class CountSummaryCalculator extends SummaryCalculator {
    constructor() {
        super(...arguments);
        this.m = 0;
    }
    get_i() {
        return "Count";
    }
    l(a, b) {
        super.l(a, b);
        this.m = 0;
    }
    c() {
        return new DefaultSummaryResult(this.j, 4, this.m);
    }
    k(a) {
        this.m++;
    }
    d(a, b, c) {
        return new DefaultSummaryResult(this.j, 4, typeGetValue(b.value) + 1);
    }
    f(a, b, c) {
        return new DefaultSummaryResult(this.j, 4, typeGetValue(b.value) - 1);
    }
    e(a, b, c, d) {
        return new DefaultSummaryResult(this.j, 4, c.value);
    }
}
CountSummaryCalculator.$t = markType(CountSummaryCalculator, 'CountSummaryCalculator', SummaryCalculator.$);
/**
 * @hidden
 */
export class AverageSummaryCalculator extends SummaryCalculator {
    constructor() {
        super(...arguments);
        this.m = 0;
        this.n = 0;
    }
    get_i() {
        return "Avg";
    }
    l(a, b) {
        super.l(a, b);
        this.m = 0;
        this.n = 0;
    }
    c() {
        let a = this.n > 0 ? this.m / this.n : 0;
        return new DefaultSummaryResult(this.j, 3, a);
    }
    k(a) {
        this.m += this.h(a);
        this.n++;
    }
    d(a, b, c) {
        let d = b.value * (c - 1);
        let e = (d - this.h(a)) / c;
        return new DefaultSummaryResult(this.j, 3, e);
    }
    f(a, b, c) {
        let d = b.value * (c + 1);
        let e = (d - this.h(a)) / c;
        return new DefaultSummaryResult(this.j, 3, e);
    }
    e(a, b, c, d) {
        let e = c.value * d;
        let f = (e - this.h(b) + this.h(a)) / d;
        return new DefaultSummaryResult(this.j, 3, f);
    }
}
AverageSummaryCalculator.$t = markType(AverageSummaryCalculator, 'AverageSummaryCalculator', SummaryCalculator.$);
/**
 * @hidden
 */
export class MaxSummaryCalculator extends SummaryCalculator {
    constructor() {
        super(...arguments);
        this.m = null;
    }
    get_i() {
        return "Max";
    }
    l(a, b) {
        super.l(a, b);
        this.m = null;
    }
    c() {
        return new DefaultSummaryResult(this.j, 1, this.m);
    }
    k(a) {
        this.m = this.n(a, this.m);
    }
    d(a, b, c) {
        let d = this.n(a, b.value);
        return new DefaultSummaryResult(this.j, 1, d);
    }
    f(a, b, c) {
        let d = this.b.getItemProperty(a, this.j);
        if (Base.equalsStatic(d, b)) {
            this.g = true;
        }
        return b;
    }
    e(a, b, c, d) {
        let e = this.n(a, c.value);
        return new DefaultSummaryResult(this.j, 1, e);
    }
    n(a, b) {
        let c = this.b.getItemProperty(a, this.j);
        if (b == null) {
            return c;
        }
        switch (this.a) {
            case 0:
                b = stringCompare(c, b) > 0 ? c : b;
                break;
            case 6:
                b = c > b ? c : b;
                break;
            case 5:
                b = c > b ? c : b;
                break;
            case 1:
                b = typeGetValue(c) > typeGetValue(b) ? c : b;
                break;
            case 3:
                b = typeGetValue(c) > typeGetValue(b) ? c : b;
                break;
            case 4:
                b = typeGetValue(c) > typeGetValue(b) ? c : b;
                break;
            case 7:
                b = c > b ? c : b;
                break;
            case 2:
                b = c ? c : b;
                break;
            case 10:
                b = typeGetValue(c) > typeGetValue(b) ? c : b;
                break;
            case 8:
                let xVal_ = c;
                let yVal_ = b;
                xVal_ = +xVal_;
                yVal_ = +yVal_;
                let d = typeGetValue(xVal_);
                let e = typeGetValue(yVal_);
                b = Base.compareSimple(d, e) > 0 ? c : b;
                break;
        }
        return b;
    }
}
MaxSummaryCalculator.$t = markType(MaxSummaryCalculator, 'MaxSummaryCalculator', SummaryCalculator.$);
/**
 * @hidden
 */
export class MinSummaryCalculator extends SummaryCalculator {
    constructor() {
        super(...arguments);
        this.m = null;
    }
    get_i() {
        return "Min";
    }
    l(a, b) {
        super.l(a, b);
        this.m = null;
    }
    c() {
        return new DefaultSummaryResult(this.j, 0, this.m);
    }
    k(a) {
        this.m = this.n(a, this.m);
    }
    d(a, b, c) {
        let d = this.n(a, b.value);
        return new DefaultSummaryResult(this.j, 0, d);
    }
    f(a, b, c) {
        let d = this.b.getItemProperty(a, this.j);
        if (Base.equalsStatic(d, b.value)) {
            this.g = true;
        }
        return b;
    }
    e(a, b, c, d) {
        let e = this.n(a, c.value);
        return new DefaultSummaryResult(this.j, 0, e);
    }
    n(a, b) {
        let c = this.b.getItemProperty(a, this.j);
        if (b == null) {
            return c;
        }
        switch (this.a) {
            case 0:
                b = stringCompare(c, b) < 0 ? c : b;
                break;
            case 6:
                b = c < b ? c : b;
                break;
            case 5:
                b = c < b ? c : b;
                break;
            case 1:
                b = typeGetValue(c) < typeGetValue(b) ? c : b;
                break;
            case 3:
                b = typeGetValue(c) < typeGetValue(b) ? c : b;
                break;
            case 4:
                b = typeGetValue(c) < typeGetValue(b) ? c : b;
                break;
            case 7:
                b = c < b ? c : b;
                break;
            case 2:
                b = !c ? c : b;
                break;
            case 10:
                b = typeGetValue(c) < typeGetValue(b) ? c : b;
                break;
            case 8:
                let xVal_ = c;
                let yVal_ = b;
                xVal_ = +xVal_;
                yVal_ = +yVal_;
                let d = typeGetValue(xVal_);
                let e = typeGetValue(yVal_);
                b = Base.compareSimple(d, e) < 0 ? c : b;
                break;
        }
        return b;
    }
}
MinSummaryCalculator.$t = markType(MinSummaryCalculator, 'MinSummaryCalculator', SummaryCalculator.$);
/**
 * @hidden
 */
export class SummaryDescription extends Base {
    constructor(a, ..._rest) {
        super();
        this.e = false;
        this.h = null;
        this.c = 0;
        this.a = null;
        a = (a == void 0) ? 0 : a;
        switch (a) {
            case 0: break;
            case 1:
                {
                    let c = _rest[0];
                    this.i = c;
                    this.d = 4;
                }
                break;
            case 2:
                {
                    let c = _rest[0];
                    let d = _rest[1];
                    this.i = c;
                    this.d = d;
                }
                break;
        }
    }
    get i() {
        return this.h;
    }
    set i(a) {
        this.h = a;
    }
    get d() {
        return this.c;
    }
    set d(a) {
        this.c = a;
        switch (this.c) {
            case 0:
                this.b = new MinSummaryCalculator();
                break;
            case 1:
                this.b = new MaxSummaryCalculator();
                break;
            case 2:
                this.b = new SumSummaryCalculator();
                break;
            case 3:
                this.b = new AverageSummaryCalculator();
                break;
            case 4:
                this.b = new CountSummaryCalculator();
                break;
        }
    }
    get b() {
        return this.a;
    }
    set b(a) {
        this.a = a;
    }
    equals(a) {
        let b = a;
        if (b == null) {
            return super.equals(a);
        }
        return b.i == this.i && b.d == this.d;
    }
    getHashCode() {
        return Base.getHashCodeStatic(this.i) * 17 + this.d;
    }
    j() {
        this.e = true;
    }
}
SummaryDescription.$t = markType(SummaryDescription, 'SummaryDescription');
/**
 * @hidden
 */
export class SummaryDescriptionCollection extends Base {
    constructor() {
        super();
        this.d = null;
        this.f = null;
        this.f = new SyncableObservableCollection$1(SummaryDescription.$);
    }
    g() {
        return this.f;
    }
    get syncTarget() {
        return this.d;
    }
    set syncTarget(a) {
        if (a == null) {
            this.f.syncTarget = null;
            this.d = null;
            return;
        }
        this.d = a;
        this.f.syncTarget = this.d.f;
    }
    add(a) {
        return this.f.add(a);
    }
    insert(a, b) {
        this.f.add1(a, b);
    }
    clear() {
        this.f.clear();
    }
    get(a) {
        return this.f.get(a);
    }
    indexOf(a) {
        return this.f.indexOf(a);
    }
    remove(a) {
        return this.f.remove1(a);
    }
    removeAt(a) {
        return this.f.remove(a);
    }
    set(a, b) {
        return this.f.set(a, b);
    }
    size() {
        return this.f.size();
    }
    n(a) {
        this.f.addListener(a);
    }
    q(a) {
        this.f.removeListener(a);
    }
    get onChanged() {
        return this.f.f;
    }
    set onChanged(a) {
        this.f.f = a;
    }
    get k() {
        return this.f.all;
    }
}
SummaryDescriptionCollection.$t = markType(SummaryDescriptionCollection, 'SummaryDescriptionCollection');
