/*
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._propertyName = null;
        this._propertyType = 0;
        this._dataSource = null;
        this._displayName = null;
        this._isSummaryDirty = false;
    }
    get propertyName() {
        return this._propertyName;
    }
    set propertyName(a) {
        this._propertyName = a;
    }
    get propertyType() {
        return this._propertyType;
    }
    set propertyType(a) {
        this._propertyType = a;
    }
    get dataSource() {
        return this._dataSource;
    }
    set dataSource(a) {
        this._dataSource = a;
    }
    get_displayName() {
        return this._displayName;
    }
    get displayName() {
        return this.get_displayName();
    }
    get isSummaryDirty() {
        return this._isSummaryDirty;
    }
    set isSummaryDirty(a) {
        this._isSummaryDirty = a;
    }
    beginCalculation(a, b) {
        this.dataSource = a;
        this.propertyName = b;
        if (this.propertyName != null) {
            this.propertyType = a.resolveSchemaPropertyType(this.propertyName);
        }
        this.isSummaryDirty = false;
    }
    endCalculation() {
        return null;
    }
    aggregate(a) {
    }
    itemAdded(a, b, c) {
        return b;
    }
    itemRemoved(a, b, c) {
        return b;
    }
    itemChanged(a, b, c, d) {
        return c;
    }
    h(a) {
        let b = this.dataSource.getItemProperty(a, this.propertyName);
        switch (this.propertyType) {
            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_displayName() {
        return "Sum";
    }
    beginCalculation(a, b) {
        super.beginCalculation(a, b);
        this.m = 0;
    }
    endCalculation() {
        return new DefaultSummaryResult(this.propertyName, 2, this.m);
    }
    aggregate(a) {
        this.m += this.h(a);
    }
    itemAdded(a, b, c) {
        let d = b.value + this.h(a);
        return new DefaultSummaryResult(this.propertyName, 2, d);
    }
    itemRemoved(a, b, c) {
        let d = b.value - this.h(a);
        return new DefaultSummaryResult(this.propertyName, 2, d);
    }
    itemChanged(a, b, c, d) {
        let e = c.value - this.h(b) + this.h(a);
        return new DefaultSummaryResult(this.propertyName, 2, e);
    }
}
SumSummaryCalculator.$t = markType(SumSummaryCalculator, 'SumSummaryCalculator', SummaryCalculator.$);
/**
 * @hidden
 */
export class CountSummaryCalculator extends SummaryCalculator {
    constructor() {
        super(...arguments);
        this.m = 0;
    }
    get_displayName() {
        return "Count";
    }
    beginCalculation(a, b) {
        super.beginCalculation(a, b);
        this.m = 0;
    }
    endCalculation() {
        return new DefaultSummaryResult(this.propertyName, 4, this.m);
    }
    aggregate(a) {
        this.m++;
    }
    itemAdded(a, b, c) {
        return new DefaultSummaryResult(this.propertyName, 4, typeGetValue(b.value) + 1);
    }
    itemRemoved(a, b, c) {
        return new DefaultSummaryResult(this.propertyName, 4, typeGetValue(b.value) - 1);
    }
    itemChanged(a, b, c, d) {
        return new DefaultSummaryResult(this.propertyName, 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_displayName() {
        return "Avg";
    }
    beginCalculation(a, b) {
        super.beginCalculation(a, b);
        this.m = 0;
        this.n = 0;
    }
    endCalculation() {
        let a = this.n > 0 ? this.m / this.n : 0;
        return new DefaultSummaryResult(this.propertyName, 3, a);
    }
    aggregate(a) {
        this.m += this.h(a);
        this.n++;
    }
    itemAdded(a, b, c) {
        let d = b.value * (c - 1);
        let e = (d - this.h(a)) / c;
        return new DefaultSummaryResult(this.propertyName, 3, e);
    }
    itemRemoved(a, b, c) {
        let d = b.value * (c + 1);
        let e = (d - this.h(a)) / c;
        return new DefaultSummaryResult(this.propertyName, 3, e);
    }
    itemChanged(a, b, c, d) {
        let e = c.value * d;
        let f = (e - this.h(b) + this.h(a)) / d;
        return new DefaultSummaryResult(this.propertyName, 3, f);
    }
}
AverageSummaryCalculator.$t = markType(AverageSummaryCalculator, 'AverageSummaryCalculator', SummaryCalculator.$);
/**
 * @hidden
 */
export class MaxSummaryCalculator extends SummaryCalculator {
    constructor() {
        super(...arguments);
        this.m = null;
    }
    get_displayName() {
        return "Max";
    }
    beginCalculation(a, b) {
        super.beginCalculation(a, b);
        this.m = null;
    }
    endCalculation() {
        return new DefaultSummaryResult(this.propertyName, 1, this.m);
    }
    aggregate(a) {
        this.m = this.n(a, this.m);
    }
    itemAdded(a, b, c) {
        let d = this.n(a, b.value);
        return new DefaultSummaryResult(this.propertyName, 1, d);
    }
    itemRemoved(a, b, c) {
        let d = this.dataSource.getItemProperty(a, this.propertyName);
        if (Base.equalsStatic(d, b)) {
            this.isSummaryDirty = true;
        }
        return b;
    }
    itemChanged(a, b, c, d) {
        let e = this.n(a, c.value);
        return new DefaultSummaryResult(this.propertyName, 1, e);
    }
    n(a, b) {
        let c = this.dataSource.getItemProperty(a, this.propertyName);
        if (b == null) {
            return c;
        }
        switch (this.propertyType) {
            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_displayName() {
        return "Min";
    }
    beginCalculation(a, b) {
        super.beginCalculation(a, b);
        this.m = null;
    }
    endCalculation() {
        return new DefaultSummaryResult(this.propertyName, 0, this.m);
    }
    aggregate(a) {
        this.m = this.n(a, this.m);
    }
    itemAdded(a, b, c) {
        let d = this.n(a, b.value);
        return new DefaultSummaryResult(this.propertyName, 0, d);
    }
    itemRemoved(a, b, c) {
        let d = this.dataSource.getItemProperty(a, this.propertyName);
        if (Base.equalsStatic(d, b.value)) {
            this.isSummaryDirty = true;
        }
        return b;
    }
    itemChanged(a, b, c, d) {
        let e = this.n(a, c.value);
        return new DefaultSummaryResult(this.propertyName, 0, e);
    }
    n(a, b) {
        let c = this.dataSource.getItemProperty(a, this.propertyName);
        if (b == null) {
            return c;
        }
        switch (this.propertyType) {
            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.propertyName = c;
                    this.operand = 4;
                }
                break;
            case 2:
                {
                    let c = _rest[0];
                    let d = _rest[1];
                    this.propertyName = c;
                    this.operand = d;
                }
                break;
        }
    }
    get propertyName() {
        return this.h;
    }
    set propertyName(a) {
        this.h = a;
    }
    get operand() {
        return this.c;
    }
    set operand(a) {
        this.c = a;
        switch (this.c) {
            case 0:
                this.calculator = new MinSummaryCalculator();
                break;
            case 1:
                this.calculator = new MaxSummaryCalculator();
                break;
            case 2:
                this.calculator = new SumSummaryCalculator();
                break;
            case 3:
                this.calculator = new AverageSummaryCalculator();
                break;
            case 4:
                this.calculator = new CountSummaryCalculator();
                break;
        }
    }
    get calculator() {
        return this.a;
    }
    set calculator(a) {
        this.a = a;
    }
    equals(a) {
        let b = a;
        if (b == null) {
            return super.equals(a);
        }
        return b.propertyName == this.propertyName && b.operand == this.operand;
    }
    getHashCode() {
        return Base.getHashCodeStatic(this.propertyName) * 17 + this.operand;
    }
    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');
