// 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 { ActorRef, ActorRefT } from '../user/actor-ref.js';


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

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

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

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

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

reasonCode():string|null
reasonCode(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
reasonCode(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;
}

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

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

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

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

static addLimitCode(builder:flatbuffers.Builder, limitCodeOffset:flatbuffers.Offset) {
  builder.addFieldOffset(0, limitCodeOffset, 0);
}

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

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

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

static addAppliedAtMs(builder:flatbuffers.Builder, appliedAtMs:bigint) {
  builder.addFieldInt64(4, appliedAtMs, BigInt('0'));
}

static addExpiresAtMs(builder:flatbuffers.Builder, expiresAtMs:bigint) {
  builder.addFieldInt64(5, expiresAtMs, BigInt('0'));
}

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


unpack(): ActiveLimitT {
  return new ActiveLimitT(
    this.limitCode(),
    this.value(),
    this.reasonCode(),
    (this.actor() !== null ? this.actor()!.unpack() : null),
    this.appliedAtMs(),
    this.expiresAtMs()
  );
}


unpackTo(_o: ActiveLimitT): void {
  _o.limitCode = this.limitCode();
  _o.value = this.value();
  _o.reasonCode = this.reasonCode();
  _o.actor = (this.actor() !== null ? this.actor()!.unpack() : null);
  _o.appliedAtMs = this.appliedAtMs();
  _o.expiresAtMs = this.expiresAtMs();
}
}

export class ActiveLimitT implements flatbuffers.IGeneratedObject {
constructor(
  public limitCode: string|Uint8Array|null = null,
  public value: bigint = BigInt('0'),
  public reasonCode: string|Uint8Array|null = null,
  public actor: ActorRefT|null = null,
  public appliedAtMs: bigint = BigInt('0'),
  public expiresAtMs: bigint = BigInt('0')
){}


pack(builder:flatbuffers.Builder): flatbuffers.Offset {
  const limitCode = (this.limitCode !== null ? builder.createString(this.limitCode!) : 0);
  const reasonCode = (this.reasonCode !== null ? builder.createString(this.reasonCode!) : 0);
  const actor = (this.actor !== null ? this.actor!.pack(builder) : 0);

  ActiveLimit.startActiveLimit(builder);
  ActiveLimit.addLimitCode(builder, limitCode);
  ActiveLimit.addValue(builder, this.value);
  ActiveLimit.addReasonCode(builder, reasonCode);
  ActiveLimit.addActor(builder, actor);
  ActiveLimit.addAppliedAtMs(builder, this.appliedAtMs);
  ActiveLimit.addExpiresAtMs(builder, this.expiresAtMs);

  return ActiveLimit.endActiveLimit(builder);
}
}
