// 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 { BattleActionReport, BattleActionReportT } from '../battle/battle-action-report.js';
import { RaceEntry, RaceEntryT } from '../battle/race-entry.js';
import { ShipEntry, ShipEntryT } from '../battle/ship-entry.js';
import { UUID, UUIDT } from '../battle/uuid.js';


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

static addShips(builder:flatbuffers.Builder, shipsOffset:flatbuffers.Offset) {
  builder.addFieldOffset(4, shipsOffset, 0);
}

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

static addProtocol(builder:flatbuffers.Builder, protocolOffset:flatbuffers.Offset) {
  builder.addFieldOffset(5, protocolOffset, 0);
}

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

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

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

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

static createBattleReport(builder:flatbuffers.Builder, idOffset:flatbuffers.Offset, planet:bigint, planetNameOffset:flatbuffers.Offset, racesOffset:flatbuffers.Offset, shipsOffset:flatbuffers.Offset, protocolOffset:flatbuffers.Offset):flatbuffers.Offset {
  BattleReport.startBattleReport(builder);
  BattleReport.addId(builder, idOffset);
  BattleReport.addPlanet(builder, planet);
  BattleReport.addPlanetName(builder, planetNameOffset);
  BattleReport.addRaces(builder, racesOffset);
  BattleReport.addShips(builder, shipsOffset);
  BattleReport.addProtocol(builder, protocolOffset);
  return BattleReport.endBattleReport(builder);
}

unpack(): BattleReportT {
  return new BattleReportT(
    (this.id() !== null ? this.id()!.unpack() : null),
    this.planet(),
    this.planetName(),
    this.bb!.createObjList<RaceEntry, RaceEntryT>(this.races.bind(this), this.racesLength()),
    this.bb!.createObjList<ShipEntry, ShipEntryT>(this.ships.bind(this), this.shipsLength()),
    this.bb!.createObjList<BattleActionReport, BattleActionReportT>(this.protocol.bind(this), this.protocolLength())
  );
}


unpackTo(_o: BattleReportT): void {
  _o.id = (this.id() !== null ? this.id()!.unpack() : null);
  _o.planet = this.planet();
  _o.planetName = this.planetName();
  _o.races = this.bb!.createObjList<RaceEntry, RaceEntryT>(this.races.bind(this), this.racesLength());
  _o.ships = this.bb!.createObjList<ShipEntry, ShipEntryT>(this.ships.bind(this), this.shipsLength());
  _o.protocol = this.bb!.createObjList<BattleActionReport, BattleActionReportT>(this.protocol.bind(this), this.protocolLength());
}
}

export class BattleReportT implements flatbuffers.IGeneratedObject {
constructor(
  public id: UUIDT|null = null,
  public planet: bigint = BigInt('0'),
  public planetName: string|Uint8Array|null = null,
  public races: (RaceEntryT)[] = [],
  public ships: (ShipEntryT)[] = [],
  public protocol: (BattleActionReportT)[] = []
){}


pack(builder:flatbuffers.Builder): flatbuffers.Offset {
  const planetName = (this.planetName !== null ? builder.createString(this.planetName!) : 0);
  const races = BattleReport.createRacesVector(builder, builder.createObjectOffsetList(this.races));
  const ships = BattleReport.createShipsVector(builder, builder.createObjectOffsetList(this.ships));
  const protocol = BattleReport.createProtocolVector(builder, builder.createObjectOffsetList(this.protocol));

  return BattleReport.createBattleReport(builder,
    (this.id !== null ? this.id!.pack(builder) : 0),
    this.planet,
    planetName,
    races,
    ships,
    protocol
  );
}
}
