// 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 { ApplicationExit, ApplicationExitT } from '../debugger/application-exit.js';
import { EmulationStatus, EmulationStatusT } from '../debugger/emulation-status.js';
import { Event, unionToEvent, unionListToEvent } from '../debugger/event.js';
import { GetStateRequest, GetStateRequestT } from '../debugger/get-state-request.js';
import { GetStateResponse, GetStateResponseT } from '../debugger/get-state-response.js';
import { PauseRequest, PauseRequestT } from '../debugger/pause-request.js';
import { ReadMemoryRequest, ReadMemoryRequestT } from '../debugger/read-memory-request.js';
import { ReadMemoryResponse, ReadMemoryResponseT } from '../debugger/read-memory-response.js';
import { ReadRegisterRequest, ReadRegisterRequestT } from '../debugger/read-register-request.js';
import { ReadRegisterResponse, ReadRegisterResponseT } from '../debugger/read-register-response.js';
import { RunRequest, RunRequestT } from '../debugger/run-request.js';
import { WriteMemoryRequest, WriteMemoryRequestT } from '../debugger/write-memory-request.js';
import { WriteMemoryResponse, WriteMemoryResponseT } from '../debugger/write-memory-response.js';
import { WriteRegisterRequest, WriteRegisterRequestT } from '../debugger/write-register-request.js';
import { WriteRegisterResponse, WriteRegisterResponseT } from '../debugger/write-register-response.js';


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

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

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

eventType():Event {
  const offset = this.bb!.__offset(this.bb_pos, 4);
  return offset ? this.bb!.readUint8(this.bb_pos + offset) : Event.NONE;
}

event<T extends flatbuffers.Table>(obj:any):any|null {
  const offset = this.bb!.__offset(this.bb_pos, 6);
  return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null;
}

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

static addEventType(builder:flatbuffers.Builder, eventType:Event) {
  builder.addFieldInt8(0, eventType, Event.NONE);
}

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

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

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

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

static createDebugEvent(builder:flatbuffers.Builder, eventType:Event, eventOffset:flatbuffers.Offset):flatbuffers.Offset {
  DebugEvent.startDebugEvent(builder);
  DebugEvent.addEventType(builder, eventType);
  DebugEvent.addEvent(builder, eventOffset);
  return DebugEvent.endDebugEvent(builder);
}

unpack(): DebugEventT {
  return new DebugEventT(
    this.eventType(),
    (() => {
      const temp = unionToEvent(this.eventType(), this.event.bind(this));
      if(temp === null) { return null; }
      return temp.unpack()
  })()
  );
}


unpackTo(_o: DebugEventT): void {
  _o.eventType = this.eventType();
  _o.event = (() => {
      const temp = unionToEvent(this.eventType(), this.event.bind(this));
      if(temp === null) { return null; }
      return temp.unpack()
  })();
}
}

export class DebugEventT implements flatbuffers.IGeneratedObject {
constructor(
  public eventType: Event = Event.NONE,
  public event: ApplicationExitT|EmulationStatusT|GetStateRequestT|GetStateResponseT|PauseRequestT|ReadMemoryRequestT|ReadMemoryResponseT|ReadRegisterRequestT|ReadRegisterResponseT|RunRequestT|WriteMemoryRequestT|WriteMemoryResponseT|WriteRegisterRequestT|WriteRegisterResponseT|null = null
){}


pack(builder:flatbuffers.Builder): flatbuffers.Offset {
  const event = builder.createObjectOffset(this.event);

  return DebugEvent.createDebugEvent(builder,
    this.eventType,
    event
  );
}
}
