// 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 { UUID, UUIDT } from '../common/uuid.js';
import { TechEntry, TechEntryT } from '../report/tech-entry.js';


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

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

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

number():bigint {
  const offset = this.bb!.__offset(this.bb_pos, 4);
  return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0');
}

class_():string|null
class_(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
class_(optionalEncoding?:any):string|Uint8Array|null {
  const offset = this.bb!.__offset(this.bb_pos, 6);
  return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
}

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

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

cargo():string|null
cargo(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
cargo(optionalEncoding?:any):string|Uint8Array|null {
  const offset = this.bb!.__offset(this.bb_pos, 10);
  return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
}

load():number {
  const offset = this.bb!.__offset(this.bb_pos, 12);
  return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 0.0;
}

destination():bigint {
  const offset = this.bb!.__offset(this.bb_pos, 14);
  return offset ? this.bb!.readUint64(this.bb_pos + offset) : BigInt('0');
}

origin():bigint|null {
  const offset = this.bb!.__offset(this.bb_pos, 16);
  return offset ? this.bb!.readUint64(this.bb_pos + offset) : null;
}

range():number|null {
  const offset = this.bb!.__offset(this.bb_pos, 18);
  return offset ? this.bb!.readFloat32(this.bb_pos + offset) : null;
}

speed():number {
  const offset = this.bb!.__offset(this.bb_pos, 20);
  return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 0.0;
}

mass():number {
  const offset = this.bb!.__offset(this.bb_pos, 22);
  return offset ? this.bb!.readFloat32(this.bb_pos + offset) : 0.0;
}

id(obj?:UUID):UUID|null {
  const offset = this.bb!.__offset(this.bb_pos, 24);
  return offset ? (obj || new UUID()).__init(this.bb_pos + offset, this.bb!) : null;
}

state():string|null
state(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
state(optionalEncoding?:any):string|Uint8Array|null {
  const offset = this.bb!.__offset(this.bb_pos, 26);
  return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
}

fleet():string|null
fleet(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
fleet(optionalEncoding?:any):string|Uint8Array|null {
  const offset = this.bb!.__offset(this.bb_pos, 28);
  return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
}

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

static addNumber(builder:flatbuffers.Builder, number:bigint) {
  builder.addFieldInt64(0, number, BigInt('0'));
}

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

static addTech(builder:flatbuffers.Builder, techOffset:flatbuffers.Offset) {
  builder.addFieldOffset(2, techOffset, 0);
}

static createTechVector(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 startTechVector(builder:flatbuffers.Builder, numElems:number) {
  builder.startVector(4, numElems, 4);
}

static addCargo(builder:flatbuffers.Builder, cargoOffset:flatbuffers.Offset) {
  builder.addFieldOffset(3, cargoOffset, 0);
}

static addLoad(builder:flatbuffers.Builder, load:number) {
  builder.addFieldFloat32(4, load, 0.0);
}

static addDestination(builder:flatbuffers.Builder, destination:bigint) {
  builder.addFieldInt64(5, destination, BigInt('0'));
}

static addOrigin(builder:flatbuffers.Builder, origin:bigint) {
  builder.addFieldInt64(6, origin, null);
}

static addRange(builder:flatbuffers.Builder, range:number) {
  builder.addFieldFloat32(7, range, null);
}

static addSpeed(builder:flatbuffers.Builder, speed:number) {
  builder.addFieldFloat32(8, speed, 0.0);
}

static addMass(builder:flatbuffers.Builder, mass:number) {
  builder.addFieldFloat32(9, mass, 0.0);
}

static addId(builder:flatbuffers.Builder, idOffset:flatbuffers.Offset) {
  builder.addFieldStruct(10, idOffset, 0);
}

static addState(builder:flatbuffers.Builder, stateOffset:flatbuffers.Offset) {
  builder.addFieldOffset(11, stateOffset, 0);
}

static addFleet(builder:flatbuffers.Builder, fleetOffset:flatbuffers.Offset) {
  builder.addFieldOffset(12, fleetOffset, 0);
}

static endLocalGroup(builder:flatbuffers.Builder):flatbuffers.Offset {
  const offset = builder.endObject();
  builder.requiredField(offset, 24) // id
  return offset;
}


unpack(): LocalGroupT {
  return new LocalGroupT(
    this.number(),
    this.class_(),
    this.bb!.createObjList<TechEntry, TechEntryT>(this.tech.bind(this), this.techLength()),
    this.cargo(),
    this.load(),
    this.destination(),
    this.origin(),
    this.range(),
    this.speed(),
    this.mass(),
    (this.id() !== null ? this.id()!.unpack() : null),
    this.state(),
    this.fleet()
  );
}


unpackTo(_o: LocalGroupT): void {
  _o.number = this.number();
  _o.class_ = this.class_();
  _o.tech = this.bb!.createObjList<TechEntry, TechEntryT>(this.tech.bind(this), this.techLength());
  _o.cargo = this.cargo();
  _o.load = this.load();
  _o.destination = this.destination();
  _o.origin = this.origin();
  _o.range = this.range();
  _o.speed = this.speed();
  _o.mass = this.mass();
  _o.id = (this.id() !== null ? this.id()!.unpack() : null);
  _o.state = this.state();
  _o.fleet = this.fleet();
}
}

export class LocalGroupT implements flatbuffers.IGeneratedObject {
constructor(
  public number: bigint = BigInt('0'),
  public class_: string|Uint8Array|null = null,
  public tech: (TechEntryT)[] = [],
  public cargo: string|Uint8Array|null = null,
  public load: number = 0.0,
  public destination: bigint = BigInt('0'),
  public origin: bigint|null = null,
  public range: number|null = null,
  public speed: number = 0.0,
  public mass: number = 0.0,
  public id: UUIDT|null = null,
  public state: string|Uint8Array|null = null,
  public fleet: string|Uint8Array|null = null
){}


pack(builder:flatbuffers.Builder): flatbuffers.Offset {
  const class_ = (this.class_ !== null ? builder.createString(this.class_!) : 0);
  const tech = LocalGroup.createTechVector(builder, builder.createObjectOffsetList(this.tech));
  const cargo = (this.cargo !== null ? builder.createString(this.cargo!) : 0);
  const state = (this.state !== null ? builder.createString(this.state!) : 0);
  const fleet = (this.fleet !== null ? builder.createString(this.fleet!) : 0);

  LocalGroup.startLocalGroup(builder);
  LocalGroup.addNumber(builder, this.number);
  LocalGroup.addClass(builder, class_);
  LocalGroup.addTech(builder, tech);
  LocalGroup.addCargo(builder, cargo);
  LocalGroup.addLoad(builder, this.load);
  LocalGroup.addDestination(builder, this.destination);
  if (this.origin !== null)
    LocalGroup.addOrigin(builder, this.origin);
  if (this.range !== null)
    LocalGroup.addRange(builder, this.range);
  LocalGroup.addSpeed(builder, this.speed);
  LocalGroup.addMass(builder, this.mass);
  LocalGroup.addId(builder, (this.id !== null ? this.id!.pack(builder) : 0));
  LocalGroup.addState(builder, state);
  LocalGroup.addFleet(builder, fleet);

  return LocalGroup.endLocalGroup(builder);
}
}
