/*
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, fromEnum, markType } from "./type";
import { List$1 } from "./List$1";
import { Transaction } from "./Transaction";
import { Dictionary$2 } from "./Dictionary$2";
import { TransactionState } from "./TransactionState";
import { ArgumentNullException } from "./ArgumentNullException";
import { stringIsNullOrWhiteSpace } from "./string";
/**
 * @hidden
 */
export let BaseTransactionService = /*@__PURE__*/ (() => {
    class BaseTransactionService extends Base {
        constructor(a, b, c) {
            super();
            this.i = false;
            this.p = new List$1(Transaction.$, 0);
            this.n = null;
            this.h = null;
            this.r = null;
            this.stateChanged = null;
            if (a == null || b == null) {
                throw new ArgumentNullException(1);
            }
            this.h = a;
            this.r = b;
            if (c != null) {
                this.n = new Dictionary$2(Base.$, TransactionState.$, 2, c);
            }
            else {
                this.n = new Dictionary$2(Base.$, TransactionState.$, 0);
            }
        }
        get m() {
            return this.i;
        }
        set m(a) {
            this.i = a;
        }
        get q() {
            return this.p;
        }
        get o() {
            return this.n;
        }
        get_l() {
            return this.i;
        }
        set_l(a) {
        }
        get l() {
            return this.get_l();
        }
        set l(a) {
            this.set_l(a);
        }
        get_k() {
            return false;
        }
        get k() {
            return this.get_k();
        }
        get_j() {
            return false;
        }
        get j() {
            return this.get_j();
        }
        af(a, b) {
            if (a.containsKey(b.id)) {
                if (this.h != null) {
                    this.h(a.item(b.id), b.value);
                }
                else {
                    a.item(b.id).value = b.value;
                }
            }
            else {
                a.addItem(b.id, new TransactionState(b.id, b.type, this.r(b.value)));
            }
        }
        aa(a, b) {
            if (this.stateChanged != null) {
                this.stateChanged(a, b);
            }
        }
        z(a, b, c) {
        }
        v(a, b = false) {
            if (this.m) {
                this.af(this.o, a);
                this.q.add(a);
            }
        }
        w(a, b = null) {
            if (a) {
                this.n.clear();
                this.p.clear();
            }
        }
        g(a) {
            if (this.o.count > 0 && this.o.containsKey(a)) {
                return this.o.item(a);
            }
            return null;
        }
        ad() {
            this.i = true;
        }
        y(a) {
            this.i = false;
            this.x();
        }
        x(a = -1) {
            if (a > -1) {
                for (let b = 0; b < this.q.count; b++) {
                    let c = this.q._inner[b];
                    if (c.transactionID == a) {
                        this.q.removeAt(b);
                        this.o.clear();
                        for (let d = 0; d < this.q.count; d++) {
                            this.af(this.o, this.q._inner[d]);
                        }
                        break;
                    }
                }
            }
            else {
                this.n.clear();
                this.p.clear();
            }
        }
        d(a) {
            for (let b = 0; b < this.q.count; b++) {
                if (this.q._inner[b].transactionID == a) {
                    return this.q._inner[b];
                }
            }
            return null;
        }
        e(a) {
            return null;
        }
        s(a, b) {
            return -1;
        }
        u(a) {
        }
        ac(a) {
        }
        ae() {
        }
        ab() {
        }
        a(a = -1) {
            let b = new List$1(TransactionState.$, 0);
            for (let c of fromEnum(this.o.values)) {
                b.add(c);
            }
            return b.toArray();
        }
        c(a = null) {
            if (a != null) {
                let b = new List$1(Transaction.$, 0);
                for (let c = 0; c < this.q.count; c++) {
                    if (this.q._inner[c].id == a) {
                        b.add(this.q._inner[c]);
                    }
                }
                return b.toArray();
            }
            return this.q.toArray();
        }
        b() {
            let a = new List$1(Transaction.$, 0);
            for (let b = 0; b < this.q.count; b++) {
                if (!stringIsNullOrWhiteSpace(this.q._inner[b].error)) {
                    a.add(this.q._inner[b]);
                }
            }
            return a.toArray();
        }
    }
    BaseTransactionService.$t = markType(BaseTransactionService, 'BaseTransactionService');
    return BaseTransactionService;
})();
