// automatically generated by the FlatBuffers compiler, do not modify

import * as flatbuffers from 'flatbuffers';

import { GameView } from '../scrabblefb/game-view.js';
import { MoveRecord } from '../scrabblefb/move-record.js';


export class MoveResult {
  bb: flatbuffers.ByteBuffer|null = null;
  bb_pos = 0;
  __init(i:number, bb:flatbuffers.ByteBuffer):MoveResult {
  this.bb_pos = i;
  this.bb = bb;
  return this;
}

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

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

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

game(obj?:GameView):GameView|null {
  const offset = this.bb!.__offset(this.bb_pos, 6);
  return offset ? (obj || new GameView()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
}

rack(index: number):number|null {
  const offset = this.bb!.__offset(this.bb_pos, 8);
  return offset ? this.bb!.readUint8(this.bb!.__vector(this.bb_pos + offset) + index) : 0;
}

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

rackArray():Uint8Array|null {
  const offset = this.bb!.__offset(this.bb_pos, 8);
  return offset ? new Uint8Array(this.bb!.bytes().buffer, this.bb!.bytes().byteOffset + this.bb!.__vector(this.bb_pos + offset), this.bb!.__vector_len(this.bb_pos + offset)) : null;
}

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

static startMoveResult(builder:flatbuffers.Builder) {
  builder.startObject(4);
}

static addMove(builder:flatbuffers.Builder, moveOffset:flatbuffers.Offset) {
  builder.addFieldOffset(0, moveOffset, 0);
}

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

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

static createRackVector(builder:flatbuffers.Builder, data:number[]|Uint8Array):flatbuffers.Offset {
  builder.startVector(1, data.length, 1);
  for (let i = data.length - 1; i >= 0; i--) {
    builder.addInt8(data[i]!);
  }
  return builder.endVector();
}

static startRackVector(builder:flatbuffers.Builder, numElems:number) {
  builder.startVector(1, numElems, 1);
}

static addBagLen(builder:flatbuffers.Builder, bagLen:number) {
  builder.addFieldInt32(3, bagLen, 0);
}

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

}
