// automatically generated by the FlatBuffers compiler, do not modify

import * as flatbuffers from 'flatbuffers';

import { Abc } from '../foobar/abc.js';
import { class_ as foobar_class_ } from '../foobar/class.js';
import { Schema, SchemaT } from '../reflection/schema.js';
import { class_ } from '../typescript/class.js';


export class Object_ implements flatbuffers.IUnpackableObject<Object_T> {
  bb: flatbuffers.ByteBuffer|null = null;
  bb_pos = 0;
  __init(i:number, bb:flatbuffers.ByteBuffer):Object_ {
  this.bb_pos = i;
  this.bb = bb;
  return this;
}

static getRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ {
  return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}

static getSizePrefixedRootAsObject(bb:flatbuffers.ByteBuffer, obj?:Object_):Object_ {
  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
  return (obj || new Object_()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}

return_():number {
  const offset = this.bb!.__offset(this.bb_pos, 4);
  return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
}

mutate_return(value:number):boolean {
  const offset = this.bb!.__offset(this.bb_pos, 4);

  if (offset === 0) {
    return false;
  }

  this.bb!.writeInt32(this.bb_pos + offset, value);
  return true;
}

if_():number {
  const offset = this.bb!.__offset(this.bb_pos, 6);
  return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
}

mutate_if(value:number):boolean {
  const offset = this.bb!.__offset(this.bb_pos, 6);

  if (offset === 0) {
    return false;
  }

  this.bb!.writeInt32(this.bb_pos + offset, value);
  return true;
}

switch_():number {
  const offset = this.bb!.__offset(this.bb_pos, 8);
  return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
}

mutate_switch(value:number):boolean {
  const offset = this.bb!.__offset(this.bb_pos, 8);

  if (offset === 0) {
    return false;
  }

  this.bb!.writeInt32(this.bb_pos + offset, value);
  return true;
}

enum_():class_ {
  const offset = this.bb!.__offset(this.bb_pos, 10);
  return offset ? this.bb!.readInt32(this.bb_pos + offset) : class_.new_;
}

mutate_enum(value:class_):boolean {
  const offset = this.bb!.__offset(this.bb_pos, 10);

  if (offset === 0) {
    return false;
  }

  this.bb!.writeInt32(this.bb_pos + offset, value);
  return true;
}

enum2():foobar_class_ {
  const offset = this.bb!.__offset(this.bb_pos, 12);
  return offset ? this.bb!.readInt32(this.bb_pos + offset) : foobar_class_.arguments_;
}

mutate_enum2(value:foobar_class_):boolean {
  const offset = this.bb!.__offset(this.bb_pos, 12);

  if (offset === 0) {
    return false;
  }

  this.bb!.writeInt32(this.bb_pos + offset, value);
  return true;
}

enum3():Abc {
  const offset = this.bb!.__offset(this.bb_pos, 14);
  return offset ? this.bb!.readInt32(this.bb_pos + offset) : Abc.a;
}

mutate_enum3(value:Abc):boolean {
  const offset = this.bb!.__offset(this.bb_pos, 14);

  if (offset === 0) {
    return false;
  }

  this.bb!.writeInt32(this.bb_pos + offset, value);
  return true;
}

reflect(obj?:Schema):Schema|null {
  const offset = this.bb!.__offset(this.bb_pos, 16);
  return offset ? (obj || new Schema()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
}

static getFullyQualifiedName():string {
  return 'typescript.Object';
}

static startObject(builder:flatbuffers.Builder) {
  builder.startObject(7);
}

static addReturn(builder:flatbuffers.Builder, return_:number) {
  builder.addFieldInt32(0, return_, 0);
}

static addIf(builder:flatbuffers.Builder, if_:number) {
  builder.addFieldInt32(1, if_, 0);
}

static addSwitch(builder:flatbuffers.Builder, switch_:number) {
  builder.addFieldInt32(2, switch_, 0);
}

static addEnum(builder:flatbuffers.Builder, enum_:class_) {
  builder.addFieldInt32(3, enum_, class_.new_);
}

static addEnum2(builder:flatbuffers.Builder, enum2:foobar_class_) {
  builder.addFieldInt32(4, enum2, foobar_class_.arguments_);
}

static addEnum3(builder:flatbuffers.Builder, enum3:Abc) {
  builder.addFieldInt32(5, enum3, Abc.a);
}

static addReflect(builder:flatbuffers.Builder, reflectOffset:flatbuffers.Offset) {
  builder.addFieldOffset(6, reflectOffset, 0);
}

static endObject(builder:flatbuffers.Builder):flatbuffers.Offset {
  const offset = builder.endObject();
  return offset;
}


unpack(): Object_T {
  return new Object_T(
    this.return_(),
    this.if_(),
    this.switch_(),
    this.enum_(),
    this.enum2(),
    this.enum3(),
    (this.reflect() !== null ? this.reflect()!.unpack() : null)
  );
}


unpackTo(_o: Object_T): void {
  _o.return_ = this.return_();
  _o.if_ = this.if_();
  _o.switch_ = this.switch_();
  _o.enum_ = this.enum_();
  _o.enum2 = this.enum2();
  _o.enum3 = this.enum3();
  _o.reflect = (this.reflect() !== null ? this.reflect()!.unpack() : null);
}
}

export class Object_T implements flatbuffers.IGeneratedObject {
constructor(
  public return_: number = 0,
  public if_: number = 0,
  public switch_: number = 0,
  public enum_: class_ = class_.new_,
  public enum2: foobar_class_ = foobar_class_.arguments_,
  public enum3: Abc = Abc.a,
  public reflect: SchemaT|null = null
){}


pack(builder:flatbuffers.Builder): flatbuffers.Offset {
  const reflect = (this.reflect !== null ? this.reflect!.pack(builder) : 0);

  Object_.startObject(builder);
  Object_.addReturn(builder, this.return_);
  Object_.addIf(builder, this.if_);
  Object_.addSwitch(builder, this.switch_);
  Object_.addEnum(builder, this.enum_);
  Object_.addEnum2(builder, this.enum2);
  Object_.addEnum3(builder, this.enum3);
  Object_.addReflect(builder, reflect);

  return Object_.endObject(builder);
}
}
