/*
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 { IDataSeriesAdapterRule_$type } from "./IDataSeriesAdapterRule";
import { List$1 } from "./List$1";
import { Base, fromEnum, EnumUtil, String_$type, markType } from "./type";
import { DataSeriesIntent_$type } from "./DataSeriesIntent";
import { DataSeries } from "./DataSeries";
import { DataSeriesMemberPathHint } from "./DataSeriesMemberPathHint";
import { truncate } from "./number";
import { stringJoin } from "./string";
var SimpleFinancialPriceSeriesRule = /** @class */ (function (_super) {
    tslib_1.__extends(SimpleFinancialPriceSeriesRule, _super);
    function SimpleFinancialPriceSeriesRule() {
        var _this = _super.call(this) || this;
        _this._priority = 0;
        _this._distinctCheckThreshold = 0;
        _this.priority = 10;
        _this.distinctCheckThreshold = 50000;
        return _this;
    }
    Object.defineProperty(SimpleFinancialPriceSeriesRule.prototype, "priority", {
        get: function () {
            return this._priority;
        },
        set: function (a) {
            this._priority = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SimpleFinancialPriceSeriesRule.prototype, "distinctCheckThreshold", {
        get: function () {
            return this._distinctCheckThreshold;
        },
        set: function (a) {
            this._distinctCheckThreshold = a;
        },
        enumerable: true,
        configurable: true
    });
    SimpleFinancialPriceSeriesRule.prototype.d = function (a, b) {
        try {
            for (var _a = tslib_1.__values(fromEnum(b)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var c = _b.value;
                if (a.contains(c)) {
                    a.remove(c);
                }
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_1) throw e_1.error; }
        }
        var e_1, _c;
    };
    SimpleFinancialPriceSeriesRule.c = function (a, b) {
        var c = a.analyzer.getAllPropertiesWithIntent(EnumUtil.getName(DataSeriesIntent_$type, (17)));
        if (c.length > 0) {
            return c[0];
        }
        return ((function (d) { return d != null ? d : a.analyzer.getFirstDateTimeProperty(); })(a.analyzer.getFirstDistinctDateTimeProperty(b)));
    };
    SimpleFinancialPriceSeriesRule.b = function (a, b) {
        var c = a.analyzer.getAllPropertiesWithIntent(EnumUtil.getName(DataSeriesIntent_$type, (17)));
        if (c.length > 0) {
            return c[0];
        }
        c = a.analyzer.getAllPropertiesWithIntent(EnumUtil.getName(DataSeriesIntent_$type, (16)));
        if (c.length > 0) {
            return c[0];
        }
        return ((function (d) { return d != null ? d : ((function (e) { return e != null ? e : ((function (f) { return f != null ? f : a.analyzer.getFirstStringProperty(); })(a.analyzer.getFirstDistinctMonotonicNumericProperty(b))); })(a.analyzer.getFirstDistinctStringProperty(b))); })(a.analyzer.getFirstDistinctDateTimeProperty(b)));
    };
    SimpleFinancialPriceSeriesRule.prototype.evaluate = function (a) {
        var b = SimpleFinancialPriceSeriesRule.c(a, this.distinctCheckThreshold);
        var c = SimpleFinancialPriceSeriesRule.b(a, this.distinctCheckThreshold);
        var d = new List$1(String_$type, 1, a.analyzer.getAllPropertiesWithIntent(EnumUtil.getName(DataSeriesIntent_$type, (11))));
        var e = new List$1(String_$type, 1, a.analyzer.getAllPropertiesWithIntent(EnumUtil.getName(DataSeriesIntent_$type, (12))));
        var f = new List$1(String_$type, 1, a.analyzer.getAllPropertiesWithIntent(EnumUtil.getName(DataSeriesIntent_$type, (13))));
        var g = new List$1(String_$type, 1, a.analyzer.getAllPropertiesWithIntent(EnumUtil.getName(DataSeriesIntent_$type, (14))));
        var h = new List$1(String_$type, 1, a.analyzer.getAllPropertiesWithIntent(EnumUtil.getName(DataSeriesIntent_$type, (15))));
        var i = Math.min(d.count, Math.min(e.count, Math.min(f.count, g.count)));
        if (i == 0) {
            var j = new List$1(String_$type, 1, a.analyzer.getAllNumericProperties());
            try {
                for (var _a = tslib_1.__values(fromEnum(j)), _b = _a.next(); !_b.done; _b = _a.next()) {
                    var k = _b.value;
                    if (Base.equalsStatic(k.toLowerCase(), "open")) {
                        d.add(k);
                        continue;
                    }
                    if (Base.equalsStatic(k.toLowerCase(), "high")) {
                        e.add(k);
                        continue;
                    }
                    if (Base.equalsStatic(k.toLowerCase(), "low")) {
                        f.add(k);
                        continue;
                    }
                    if (Base.equalsStatic(k.toLowerCase(), "close")) {
                        g.add(k);
                        continue;
                    }
                    if (Base.equalsStatic(k.toLowerCase(), "volume")) {
                        h.add(k);
                        continue;
                    }
                }
            }
            catch (e_2_1) { e_2 = { error: e_2_1 }; }
            finally {
                try {
                    if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
                }
                finally { if (e_2) throw e_2.error; }
            }
            this.d(j, d);
            this.d(j, e);
            this.d(j, f);
            this.d(j, g);
            this.d(j, h);
            var l = d.count + e.count + f.count + g.count + j.count;
            if (l == 0) {
                return;
            }
            i = l <= 4 ? 1 : truncate(Math.floor(l / 5));
            var m = [d, e, f, g, h];
            var n = 0;
            while (j.count > 0) {
                m[n++ % m.length].add(j._inner[0]);
                j.removeAt(0);
            }
        }
        var _loop_1 = function (o) {
            var p = d.count > o ? d._inner[o] : null;
            var q = e.count > o ? e._inner[o] : null;
            var r = f.count > o ? f._inner[o] : null;
            var s = g.count > o ? g._inner[o] : null;
            var t = ((function () {
                var $ret = new DataSeries();
                $ret.name = stringJoin("_", p, q, r, s);
                $ret.title = a.analyzer.getTitleString(null, [p, q, r, s]);
                $ret.suggestedSeries = 20;
                $ret.suggestedPrimaryAxis = 0;
                $ret.suggestedSecondaryAxis = 1;
                return $ret;
            })());
            t.addMemberPathHint(((function () {
                var $ret = new DataSeriesMemberPathHint();
                $ret.intent = 11;
                $ret.path = p;
                return $ret;
            })()));
            t.addMemberPathHint(((function () {
                var $ret = new DataSeriesMemberPathHint();
                $ret.intent = 12;
                $ret.path = q;
                return $ret;
            })()));
            t.addMemberPathHint(((function () {
                var $ret = new DataSeriesMemberPathHint();
                $ret.intent = 13;
                $ret.path = r;
                return $ret;
            })()));
            t.addMemberPathHint(((function () {
                var $ret = new DataSeriesMemberPathHint();
                $ret.intent = 14;
                $ret.path = s;
                return $ret;
            })()));
            if (h.count > o) {
                t.addMemberPathHint(((function () {
                    var $ret = new DataSeriesMemberPathHint();
                    $ret.intent = 15;
                    $ret.path = h._inner[o];
                    return $ret;
                })()));
            }
            if (b != null) {
                t.addMemberPathHint(((function () {
                    var $ret = new DataSeriesMemberPathHint();
                    $ret.intent = 17;
                    $ret.path = b;
                    return $ret;
                })()));
            }
            t.addMemberPathHint(((function () {
                var $ret = new DataSeriesMemberPathHint();
                $ret.intent = 16;
                $ret.path = c;
                return $ret;
            })()));
            a.addDataSeries(t, this_1);
        };
        var this_1 = this;
        for (var o = 0; o < i; o++) {
            _loop_1(o);
        }
        var e_2, _c;
    };
    SimpleFinancialPriceSeriesRule.$t = markType(SimpleFinancialPriceSeriesRule, 'SimpleFinancialPriceSeriesRule', Base.$, [IDataSeriesAdapterRule_$type]);
    return SimpleFinancialPriceSeriesRule;
}(Base));
export { SimpleFinancialPriceSeriesRule };
//# sourceMappingURL=SimpleFinancialPriceSeriesRule.js.map