# automatically generated by the FlatBuffers compiler, do not modify

# namespace: FlatGeobuf

import flatbuffers
from flatbuffers.compat import import_numpy
from typing import Any
from .Column import Column
from .Crs import Crs
from typing import Optional
np = import_numpy()

class Header(object):
    __slots__ = ['_tab']

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

    @classmethod
    def GetRootAsHeader(cls, buf, offset=0):
        """This method is deprecated. Please switch to GetRootAs."""
        return cls.GetRootAs(buf, offset)
    # Header
    def Init(self, buf: bytes, pos: int):
        self._tab = flatbuffers.table.Table(buf, pos)

    # Header
    def Name(self) -> Optional[str]:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # Header
    def Envelope(self, j: int):
        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.Float64Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 8))
        return 0

    # Header
    def EnvelopeAsNumpy(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Float64Flags, o)
        return 0

    # Header
    def EnvelopeLength(self) -> int:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # Header
    def EnvelopeIsNone(self) -> bool:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        return o == 0

    # Header
    def GeometryType(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos)
        return 0

    # Header
    def HasZ(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
        if o != 0:
            return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
        return False

    # Header
    def HasM(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
        if o != 0:
            return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
        return False

    # Header
    def HasT(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
        if o != 0:
            return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
        return False

    # Header
    def HasTm(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16))
        if o != 0:
            return bool(self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos))
        return False

    # Header
    def Columns(self, j: int) -> Optional[Column]:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18))
        if o != 0:
            x = self._tab.Vector(o)
            x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
            x = self._tab.Indirect(x)
            obj = Column()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

    # Header
    def ColumnsLength(self) -> int:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # Header
    def ColumnsIsNone(self) -> bool:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18))
        return o == 0

    # Header
    def FeaturesCount(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(20))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint64Flags, o + self._tab.Pos)
        return 0

    # Header
    def IndexNodeSize(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(22))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint16Flags, o + self._tab.Pos)
        return 16

    # Header
    def Crs(self) -> Optional[Crs]:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(24))
        if o != 0:
            x = self._tab.Indirect(o + self._tab.Pos)
            obj = Crs()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

    # Header
    def Title(self) -> Optional[str]:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(26))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # Header
    def Description(self) -> Optional[str]:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(28))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # Header
    def Metadata(self) -> Optional[str]:
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(30))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

def HeaderStart(builder: flatbuffers.Builder):
    builder.StartObject(14)

def Start(builder: flatbuffers.Builder):
    HeaderStart(builder)

def HeaderAddName(builder: flatbuffers.Builder, name: int):
    builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0)

def AddName(builder: flatbuffers.Builder, name: int):
    HeaderAddName(builder, name)

def HeaderAddEnvelope(builder: flatbuffers.Builder, envelope: int):
    builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(envelope), 0)

def AddEnvelope(builder: flatbuffers.Builder, envelope: int):
    HeaderAddEnvelope(builder, envelope)

def HeaderStartEnvelopeVector(builder, numElems: int) -> int:
    return builder.StartVector(8, numElems, 8)

def StartEnvelopeVector(builder, numElems: int) -> int:
    return HeaderStartEnvelopeVector(builder, numElems)

def HeaderAddGeometryType(builder: flatbuffers.Builder, geometryType: int):
    builder.PrependUint8Slot(2, geometryType, 0)

def AddGeometryType(builder: flatbuffers.Builder, geometryType: int):
    HeaderAddGeometryType(builder, geometryType)

def HeaderAddHasZ(builder: flatbuffers.Builder, hasZ: bool):
    builder.PrependBoolSlot(3, hasZ, 0)

def AddHasZ(builder: flatbuffers.Builder, hasZ: bool):
    HeaderAddHasZ(builder, hasZ)

def HeaderAddHasM(builder: flatbuffers.Builder, hasM: bool):
    builder.PrependBoolSlot(4, hasM, 0)

def AddHasM(builder: flatbuffers.Builder, hasM: bool):
    HeaderAddHasM(builder, hasM)

def HeaderAddHasT(builder: flatbuffers.Builder, hasT: bool):
    builder.PrependBoolSlot(5, hasT, 0)

def AddHasT(builder: flatbuffers.Builder, hasT: bool):
    HeaderAddHasT(builder, hasT)

def HeaderAddHasTm(builder: flatbuffers.Builder, hasTm: bool):
    builder.PrependBoolSlot(6, hasTm, 0)

def AddHasTm(builder: flatbuffers.Builder, hasTm: bool):
    HeaderAddHasTm(builder, hasTm)

def HeaderAddColumns(builder: flatbuffers.Builder, columns: int):
    builder.PrependUOffsetTRelativeSlot(7, flatbuffers.number_types.UOffsetTFlags.py_type(columns), 0)

def AddColumns(builder: flatbuffers.Builder, columns: int):
    HeaderAddColumns(builder, columns)

def HeaderStartColumnsVector(builder, numElems: int) -> int:
    return builder.StartVector(4, numElems, 4)

def StartColumnsVector(builder, numElems: int) -> int:
    return HeaderStartColumnsVector(builder, numElems)

def HeaderAddFeaturesCount(builder: flatbuffers.Builder, featuresCount: int):
    builder.PrependUint64Slot(8, featuresCount, 0)

def AddFeaturesCount(builder: flatbuffers.Builder, featuresCount: int):
    HeaderAddFeaturesCount(builder, featuresCount)

def HeaderAddIndexNodeSize(builder: flatbuffers.Builder, indexNodeSize: int):
    builder.PrependUint16Slot(9, indexNodeSize, 16)

def AddIndexNodeSize(builder: flatbuffers.Builder, indexNodeSize: int):
    HeaderAddIndexNodeSize(builder, indexNodeSize)

def HeaderAddCrs(builder: flatbuffers.Builder, crs: int):
    builder.PrependUOffsetTRelativeSlot(10, flatbuffers.number_types.UOffsetTFlags.py_type(crs), 0)

def AddCrs(builder: flatbuffers.Builder, crs: int):
    HeaderAddCrs(builder, crs)

def HeaderAddTitle(builder: flatbuffers.Builder, title: int):
    builder.PrependUOffsetTRelativeSlot(11, flatbuffers.number_types.UOffsetTFlags.py_type(title), 0)

def AddTitle(builder: flatbuffers.Builder, title: int):
    HeaderAddTitle(builder, title)

def HeaderAddDescription(builder: flatbuffers.Builder, description: int):
    builder.PrependUOffsetTRelativeSlot(12, flatbuffers.number_types.UOffsetTFlags.py_type(description), 0)

def AddDescription(builder: flatbuffers.Builder, description: int):
    HeaderAddDescription(builder, description)

def HeaderAddMetadata(builder: flatbuffers.Builder, metadata: int):
    builder.PrependUOffsetTRelativeSlot(13, flatbuffers.number_types.UOffsetTFlags.py_type(metadata), 0)

def AddMetadata(builder: flatbuffers.Builder, metadata: int):
    HeaderAddMetadata(builder, metadata)

def HeaderEnd(builder: flatbuffers.Builder) -> int:
    return builder.EndObject()

def End(builder: flatbuffers.Builder) -> int:
    return HeaderEnd(builder)
