// automatically generated by the FlatBuffers compiler, do not modify
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any,
 * @typescript-eslint/no-non-null-assertion */
import * as flatbuffers from 'flatbuffers';

import {Field} from '../reflection/field.js';
import {KeyValue} from '../reflection/key-value.js';

export class Object_ {
  constructor() {
    this.bb = null;
    this.bb_pos = 0;
  }
  __init(i, bb) {
    this.bb_pos = i;
    this.bb = bb;
    return this;
  }
  static getRootAsObject(bb, obj) {
    return (obj || new Object_())
        .__init(bb.readInt32(bb.position()) + bb.position(), bb);
  }
  static getSizePrefixedRootAsObject(bb, obj) {
    bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
    return (obj || new Object_())
        .__init(bb.readInt32(bb.position()) + bb.position(), bb);
  }
  name(optionalEncoding) {
    const offset = this.bb.__offset(this.bb_pos, 4);
    return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) :
                    null;
  }
  fields(index, obj) {
    const offset = this.bb.__offset(this.bb_pos, 6);
    return offset ?
        (obj || new Field())
            .__init(
                this.bb.__indirect(
                    this.bb.__vector(this.bb_pos + offset) + index * 4),
                this.bb) :
        null;
  }
  fieldsLength() {
    const offset = this.bb.__offset(this.bb_pos, 6);
    return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
  }
  isStruct() {
    const offset = this.bb.__offset(this.bb_pos, 8);
    return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false;
  }
  mutate_is_struct(value) {
    const offset = this.bb.__offset(this.bb_pos, 8);
    if (offset === 0) {
      return false;
    }
    this.bb.writeInt8(this.bb_pos + offset, +value);
    return true;
  }
  minalign() {
    const offset = this.bb.__offset(this.bb_pos, 10);
    return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
  }
  mutate_minalign(value) {
    const offset = this.bb.__offset(this.bb_pos, 10);
    if (offset === 0) {
      return false;
    }
    this.bb.writeInt32(this.bb_pos + offset, value);
    return true;
  }
  bytesize() {
    const offset = this.bb.__offset(this.bb_pos, 12);
    return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
  }
  mutate_bytesize(value) {
    const offset = this.bb.__offset(this.bb_pos, 12);
    if (offset === 0) {
      return false;
    }
    this.bb.writeInt32(this.bb_pos + offset, value);
    return true;
  }
  attributes(index, obj) {
    const offset = this.bb.__offset(this.bb_pos, 14);
    return offset ?
        (obj || new KeyValue())
            .__init(
                this.bb.__indirect(
                    this.bb.__vector(this.bb_pos + offset) + index * 4),
                this.bb) :
        null;
  }
  attributesLength() {
    const offset = this.bb.__offset(this.bb_pos, 14);
    return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
  }
  documentation(index, optionalEncoding) {
    const offset = this.bb.__offset(this.bb_pos, 16);
    return offset ? this.bb.__string(
                        this.bb.__vector(this.bb_pos + offset) + index * 4,
                        optionalEncoding) :
                    null;
  }
  documentationLength() {
    const offset = this.bb.__offset(this.bb_pos, 16);
    return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
  }
  declarationFile(optionalEncoding) {
    const offset = this.bb.__offset(this.bb_pos, 18);
    return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) :
                    null;
  }
  static getFullyQualifiedName() {
    return 'reflection.Object';
  }
  static startObject(builder) {
    builder.startObject(8);
  }
  static addName(builder, nameOffset) {
    builder.addFieldOffset(0, nameOffset, 0);
  }
  static addFields(builder, fieldsOffset) {
    builder.addFieldOffset(1, fieldsOffset, 0);
  }
  static createFieldsVector(builder, data) {
    builder.startVector(4, data.length, 4);
    for (let i = data.length - 1; i >= 0; i--) {
      builder.addOffset(data[i]);
    }
    return builder.endVector();
  }
  static startFieldsVector(builder, numElems) {
    builder.startVector(4, numElems, 4);
  }
  static addIsStruct(builder, isStruct) {
    builder.addFieldInt8(2, +isStruct, +false);
  }
  static addMinalign(builder, minalign) {
    builder.addFieldInt32(3, minalign, 0);
  }
  static addBytesize(builder, bytesize) {
    builder.addFieldInt32(4, bytesize, 0);
  }
  static addAttributes(builder, attributesOffset) {
    builder.addFieldOffset(5, attributesOffset, 0);
  }
  static createAttributesVector(builder, data) {
    builder.startVector(4, data.length, 4);
    for (let i = data.length - 1; i >= 0; i--) {
      builder.addOffset(data[i]);
    }
    return builder.endVector();
  }
  static startAttributesVector(builder, numElems) {
    builder.startVector(4, numElems, 4);
  }
  static addDocumentation(builder, documentationOffset) {
    builder.addFieldOffset(6, documentationOffset, 0);
  }
  static createDocumentationVector(builder, data) {
    builder.startVector(4, data.length, 4);
    for (let i = data.length - 1; i >= 0; i--) {
      builder.addOffset(data[i]);
    }
    return builder.endVector();
  }
  static startDocumentationVector(builder, numElems) {
    builder.startVector(4, numElems, 4);
  }
  static addDeclarationFile(builder, declarationFileOffset) {
    builder.addFieldOffset(7, declarationFileOffset, 0);
  }
  static endObject(builder) {
    const offset = builder.endObject();
    builder.requiredField(offset, 4);  // name
    builder.requiredField(offset, 6);  // fields
    return offset;
  }
  static createObject(
      builder, nameOffset, fieldsOffset, isStruct, minalign, bytesize,
      attributesOffset, documentationOffset, declarationFileOffset) {
    Object_.startObject(builder);
    Object_.addName(builder, nameOffset);
    Object_.addFields(builder, fieldsOffset);
    Object_.addIsStruct(builder, isStruct);
    Object_.addMinalign(builder, minalign);
    Object_.addBytesize(builder, bytesize);
    Object_.addAttributes(builder, attributesOffset);
    Object_.addDocumentation(builder, documentationOffset);
    Object_.addDeclarationFile(builder, declarationFileOffset);
    return Object_.endObject(builder);
  }
  unpack() {
    return new Object_T(
        this.name(),
        this.bb.createObjList(this.fields.bind(this), this.fieldsLength()),
        this.isStruct(), this.minalign(), this.bytesize(),
        this.bb.createObjList(
            this.attributes.bind(this), this.attributesLength()),
        this.bb.createScalarList(
            this.documentation.bind(this), this.documentationLength()),
        this.declarationFile());
  }
  unpackTo(_o) {
    _o.name = this.name();
    _o.fields =
        this.bb.createObjList(this.fields.bind(this), this.fieldsLength());
    _o.isStruct = this.isStruct();
    _o.minalign = this.minalign();
    _o.bytesize = this.bytesize();
    _o.attributes = this.bb.createObjList(
        this.attributes.bind(this), this.attributesLength());
    _o.documentation = this.bb.createScalarList(
        this.documentation.bind(this), this.documentationLength());
    _o.declarationFile = this.declarationFile();
  }
}
export class Object_T {
  constructor(
      name = null, fields = [], isStruct = false, minalign = 0, bytesize = 0,
      attributes = [], documentation = [], declarationFile = null) {
    this.name = name;
    this.fields = fields;
    this.isStruct = isStruct;
    this.minalign = minalign;
    this.bytesize = bytesize;
    this.attributes = attributes;
    this.documentation = documentation;
    this.declarationFile = declarationFile;
  }
  pack(builder) {
    const name = (this.name !== null ? builder.createString(this.name) : 0);
    const fields = Object_.createFieldsVector(
        builder, builder.createObjectOffsetList(this.fields));
    const attributes = Object_.createAttributesVector(
        builder, builder.createObjectOffsetList(this.attributes));
    const documentation = Object_.createDocumentationVector(
        builder, builder.createObjectOffsetList(this.documentation));
    const declarationFile =
        (this.declarationFile !== null ?
             builder.createString(this.declarationFile) :
             0);
    return Object_.createObject(
        builder, name, fields, this.isStruct, this.minalign, this.bytesize,
        attributes, documentation, declarationFile);
  }
}
