# automatically generated by the FlatBuffers compiler, do not modify

# namespace: xbrmm

import flatbuffers
from flatbuffers.compat import import_numpy

np = import_numpy()


# Current channel off-chain balance. The sum of ``Balance.remaining`` and ``Balance.inflight`` equals ``Channel.amount``.
class ChannelBalance(object):
    __slots__ = ["_tab"]

    @classmethod
    def GetRootAs(cls, buf, offset=0):
        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
        x = ChannelBalance()
        x.Init(buf, n + offset)
        return x

    @classmethod
    def GetRootAsChannelBalance(cls, buf, offset=0):
        """This method is deprecated. Please switch to GetRootAs."""
        return cls.GetRootAs(buf, offset)

    # ChannelBalance
    def Init(self, buf, pos):
        self._tab = flatbuffers.table.Table(buf, pos)

    # Amount of ERC20 tokens (of the market coin type) currently remaining in the channel.
    # ChannelBalance
    def Remaining(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            a = self._tab.Vector(o)
            return self._tab.Get(
                flatbuffers.number_types.Uint8Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1)
            )
        return 0

    # ChannelBalance
    def RemainingAsNumpy(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Uint8Flags, o)
        return 0

    # ChannelBalance
    def RemainingLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # ChannelBalance
    def RemainingIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        return o == 0

    # Amount of ERC20 tokens (of the market coin type) reserved to in-flight transactions.
    # ChannelBalance
    def Inflight(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            a = self._tab.Vector(o)
            return self._tab.Get(
                flatbuffers.number_types.Uint8Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1)
            )
        return 0

    # ChannelBalance
    def InflightAsNumpy(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Uint8Flags, o)
        return 0

    # ChannelBalance
    def InflightLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # ChannelBalance
    def InflightIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        return o == 0

    # Sequence number of transactions on this balance starting from 0 when the channel is created.
    # ChannelBalance
    def Seq(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos)
        return 0


def ChannelBalanceStart(builder):
    builder.StartObject(3)


def Start(builder):
    ChannelBalanceStart(builder)


def ChannelBalanceAddRemaining(builder, remaining):
    builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(remaining), 0)


def AddRemaining(builder, remaining):
    ChannelBalanceAddRemaining(builder, remaining)


def ChannelBalanceStartRemainingVector(builder, numElems):
    return builder.StartVector(1, numElems, 1)


def StartRemainingVector(builder, numElems: int) -> int:
    return ChannelBalanceStartRemainingVector(builder, numElems)


def ChannelBalanceAddInflight(builder, inflight):
    builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(inflight), 0)


def AddInflight(builder, inflight):
    ChannelBalanceAddInflight(builder, inflight)


def ChannelBalanceStartInflightVector(builder, numElems):
    return builder.StartVector(1, numElems, 1)


def StartInflightVector(builder, numElems: int) -> int:
    return ChannelBalanceStartInflightVector(builder, numElems)


def ChannelBalanceAddSeq(builder, seq):
    builder.PrependUint32Slot(2, seq, 0)


def AddSeq(builder, seq):
    ChannelBalanceAddSeq(builder, seq)


def ChannelBalanceEnd(builder):
    return builder.EndObject()


def End(builder):
    return ChannelBalanceEnd(builder)
