// 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 { CommandItem, CommandItemT } from '../order/command-item.js';


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

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

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

gameId(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;
}

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

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

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

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

static addGameId(builder:flatbuffers.Builder, gameIdOffset:flatbuffers.Offset) {
  builder.addFieldStruct(0, gameIdOffset, 0);
}

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

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

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

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

static createUserGamesOrder(builder:flatbuffers.Builder, gameIdOffset:flatbuffers.Offset, updatedAt:bigint, commandsOffset:flatbuffers.Offset):flatbuffers.Offset {
  UserGamesOrder.startUserGamesOrder(builder);
  UserGamesOrder.addGameId(builder, gameIdOffset);
  UserGamesOrder.addUpdatedAt(builder, updatedAt);
  UserGamesOrder.addCommands(builder, commandsOffset);
  return UserGamesOrder.endUserGamesOrder(builder);
}

unpack(): UserGamesOrderT {
  return new UserGamesOrderT(
    (this.gameId() !== null ? this.gameId()!.unpack() : null),
    this.updatedAt(),
    this.bb!.createObjList<CommandItem, CommandItemT>(this.commands.bind(this), this.commandsLength())
  );
}


unpackTo(_o: UserGamesOrderT): void {
  _o.gameId = (this.gameId() !== null ? this.gameId()!.unpack() : null);
  _o.updatedAt = this.updatedAt();
  _o.commands = this.bb!.createObjList<CommandItem, CommandItemT>(this.commands.bind(this), this.commandsLength());
}
}

export class UserGamesOrderT implements flatbuffers.IGeneratedObject {
constructor(
  public gameId: UUIDT|null = null,
  public updatedAt: bigint = BigInt('0'),
  public commands: (CommandItemT)[] = []
){}


pack(builder:flatbuffers.Builder): flatbuffers.Offset {
  const commands = UserGamesOrder.createCommandsVector(builder, builder.createObjectOffsetList(this.commands));

  return UserGamesOrder.createUserGamesOrder(builder,
    (this.gameId !== null ? this.gameId!.pack(builder) : 0),
    this.updatedAt,
    commands
  );
}
}
