"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class SteemOperationNumber {
    constructor(blockNum, transactionNum, operationNum = 0) {
        this.blockNum = blockNum;
        this.transactionNum = transactionNum;
        this.operationNum = operationNum;
    }
    isGreaterThan(tn) {
        if (this.blockNum > tn.blockNum)
            return true;
        else if (this.blockNum == tn.blockNum && this.transactionNum > tn.transactionNum)
            return true;
        else if (this.blockNum == tn.blockNum && this.transactionNum == tn.transactionNum)
            return this.operationNum > tn.operationNum;
        else
            return false;
    }
    isGreaterOrEqual(tn) {
        if (this.blockNum > tn.blockNum)
            return true;
        else if (this.blockNum == tn.blockNum && this.transactionNum > tn.transactionNum)
            return true;
        else if (this.blockNum == tn.blockNum && this.transactionNum == tn.transactionNum)
            return this.operationNum >= tn.operationNum;
        else
            return false;
    }
    isLesserThan(tn) {
        if (this.blockNum < tn.blockNum)
            return true;
        else if (this.blockNum == tn.blockNum && this.transactionNum < tn.transactionNum)
            return true;
        else if (this.blockNum == tn.blockNum && this.transactionNum == tn.transactionNum)
            return this.operationNum < tn.operationNum;
        else
            return false;
    }
    /**
     * There is a bug in account_history api: op_in_trx is always zero in returned operations.
     * This prevents proper comparison of SteemOperationNumbers. Thuswe have to use the following hack in some places.
     * Issue: https://github.com/steemit/steem/issues/2272 It is solved, but in api.steemit.com endpoint the bug still exists.
     * TODO: Stop using this function when the bug is solved. There is a separate function, because it would be
     * dangerous (easy to forget about) to solve the bug implicitly.
     */
    isLesserThan_solveOpInTrxBug(tn) {
        if (this.blockNum < tn.blockNum)
            return true;
        else if (this.blockNum == tn.blockNum && this.transactionNum <= (tn.transactionNum - 1))
            return true;
        else
            return false;
    }
    isLesserOrEqual(tn) {
        if (this.blockNum < tn.blockNum)
            return true;
        else if (this.blockNum == tn.blockNum && this.transactionNum < tn.transactionNum)
            return true;
        else if (this.blockNum == tn.blockNum && this.transactionNum == tn.transactionNum)
            return this.operationNum <= tn.operationNum;
        else
            return false;
    }
    isEqual(tn) {
        return this.blockNum == tn.blockNum && this.transactionNum == tn.transactionNum && this.operationNum == tn.operationNum;
    }
    /**
     * There is a bug in account_history api: op_in_trx is always zero in returned operations.
     * This prevents proper comparison of SteemOperationNumbers. Thuswe have to use the following hack in some places.
     * Issue: https://github.com/steemit/steem/issues/2272 It is solved, but in api.steemit.com endpoint the bug still exists.
     * TODO: Stop using this function when the bug is solved. There is a separate function, because it would be
     * dangerous (easy to forget about) to solve the bug implicitly.
     */
    isEqual_solveOpInTrxBug(tn) {
        return this.blockNum == tn.blockNum && this.transactionNum == tn.transactionNum;
    }
    addTransactions(txNum) {
        return new SteemOperationNumber(this.blockNum, this.transactionNum + txNum, this.operationNum);
    }
    toString() {
        return "[b=" + this.blockNum + ", tx=" + this.transactionNum + ", op=" + this.operationNum + "]";
    }
    static fromTransaction(op, operationNum = 0) {
        return new SteemOperationNumber(op.block_num, op.transaction_num, operationNum);
    }
    static compare(sonA, sonB) {
        if (sonA.blockNum === sonB.blockNum) {
            if (sonA.transactionNum === sonB.transactionNum)
                return sonA.operationNum - sonB.operationNum;
            else
                return sonA.transactionNum - sonB.transactionNum;
        }
        else
            return sonA.blockNum - sonB.blockNum;
    }
    clone() {
        return new SteemOperationNumber(this.blockNum, this.transactionNum, this.operationNum);
    }
}
SteemOperationNumber.FUTURE = new SteemOperationNumber(Infinity, Infinity, Infinity);
SteemOperationNumber.NOW = SteemOperationNumber.FUTURE;
SteemOperationNumber.NEVER = new SteemOperationNumber(-1, -1, -1);
exports.SteemOperationNumber = SteemOperationNumber;
//# sourceMappingURL=SteemOperationNumber.js.map