// 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 { RouteEntry, RouteEntryT } from '../report/route-entry.js';


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

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

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

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

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

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

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

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

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

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

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

static createRoute(builder:flatbuffers.Builder, planet:bigint, routeOffset:flatbuffers.Offset):flatbuffers.Offset {
  Route.startRoute(builder);
  Route.addPlanet(builder, planet);
  Route.addRoute(builder, routeOffset);
  return Route.endRoute(builder);
}

unpack(): RouteT {
  return new RouteT(
    this.planet(),
    this.bb!.createObjList<RouteEntry, RouteEntryT>(this.route.bind(this), this.routeLength())
  );
}


unpackTo(_o: RouteT): void {
  _o.planet = this.planet();
  _o.route = this.bb!.createObjList<RouteEntry, RouteEntryT>(this.route.bind(this), this.routeLength());
}
}

export class RouteT implements flatbuffers.IGeneratedObject {
constructor(
  public planet: bigint = BigInt('0'),
  public route: (RouteEntryT)[] = []
){}


pack(builder:flatbuffers.Builder): flatbuffers.Offset {
  const route = Route.createRouteVector(builder, builder.createObjectOffsetList(this.route));

  return Route.createRoute(builder,
    this.planet,
    route
  );
}
}
