// 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 { Galaxy } from '../../flatbuffers/goldens/galaxy.js';


export class Universe {
  bb: flatbuffers.ByteBuffer|null = null;
  bb_pos = 0;
  __init(i:number, bb:flatbuffers.ByteBuffer):Universe {
  this.bb_pos = i;
  this.bb = bb;
  return this;
}

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

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

age():number {
  const offset = this.bb!.__offset(this.bb_pos, 4);
  return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 0.0;
}

galaxies(index: number, obj?:Galaxy):Galaxy|null {
  const offset = this.bb!.__offset(this.bb_pos, 6);
  return offset ? (obj || new Galaxy()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
}

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

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

static addAge(builder:flatbuffers.Builder, age:number) {
  builder.addFieldFloat64(0, age, 0.0);
}

static addGalaxies(builder:flatbuffers.Builder, galaxiesOffset:flatbuffers.Offset) {
  builder.addFieldOffset(1, galaxiesOffset, 0);
}

static createGalaxiesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
  builder.startVector(4, data.length, 4);
  for (let i = data.length - 1; i >= 0; i--) {
    builder.addOffset(data[i]!);
  }
  return builder.endVector();
}

static startGalaxiesVector(builder:flatbuffers.Builder, numElems:number) {
  builder.startVector(4, numElems, 4);
}

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

static finishUniverseBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
  builder.finish(offset);
}

static finishSizePrefixedUniverseBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
  builder.finish(offset, undefined, true);
}

static createUniverse(builder:flatbuffers.Builder, age:number, galaxiesOffset:flatbuffers.Offset):flatbuffers.Offset {
  Universe.startUniverse(builder);
  Universe.addAge(builder, age);
  Universe.addGalaxies(builder, galaxiesOffset);
  return Universe.endUniverse(builder);
}
}
