// 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 UserGamesOrderResponse implements flatbuffers.IUnpackableObject<UserGamesOrderResponseT> {
  bb: flatbuffers.ByteBuffer|null = null;
  bb_pos = 0;
  __init(i:number, bb:flatbuffers.ByteBuffer):UserGamesOrderResponse {
  this.bb_pos = i;
  this.bb = bb;
  return this;
}

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

static getSizePrefixedRootAsUserGamesOrderResponse(bb:flatbuffers.ByteBuffer, obj?:UserGamesOrderResponse):UserGamesOrderResponse {
  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
  return (obj || new UserGamesOrderResponse()).__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 startUserGamesOrderResponse(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 endUserGamesOrderResponse(builder:flatbuffers.Builder):flatbuffers.Offset {
  const offset = builder.endObject();
  return offset;
}

static createUserGamesOrderResponse(builder:flatbuffers.Builder, gameIdOffset:flatbuffers.Offset, updatedAt:bigint, commandsOffset:flatbuffers.Offset):flatbuffers.Offset {
  UserGamesOrderResponse.startUserGamesOrderResponse(builder);
  UserGamesOrderResponse.addGameId(builder, gameIdOffset);
  UserGamesOrderResponse.addUpdatedAt(builder, updatedAt);
  UserGamesOrderResponse.addCommands(builder, commandsOffset);
  return UserGamesOrderResponse.endUserGamesOrderResponse(builder);
}

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


unpackTo(_o: UserGamesOrderResponseT): 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 UserGamesOrderResponseT 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 = UserGamesOrderResponse.createCommandsVector(builder, builder.createObjectOffsetList(this.commands));

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