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

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

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

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

isPaid():boolean {
  const offset = this.bb!.__offset(this.bb_pos, 6);
  return offset ? !!this.bb!.readInt8(this.bb_pos + offset) : false;
}

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

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

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

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

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

static startEntitlementSnapshot(builder:flatbuffers.Builder) {
  builder.startObject(8);
}

static addPlanCode(builder:flatbuffers.Builder, planCodeOffset:flatbuffers.Offset) {
  builder.addFieldOffset(0, planCodeOffset, 0);
}

static addIsPaid(builder:flatbuffers.Builder, isPaid:boolean) {
  builder.addFieldInt8(1, +isPaid, +false);
}

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

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

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

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

static addEndsAtMs(builder:flatbuffers.Builder, endsAtMs:bigint) {
  builder.addFieldInt64(6, endsAtMs, BigInt('0'));
}

static addUpdatedAtMs(builder:flatbuffers.Builder, updatedAtMs:bigint) {
  builder.addFieldInt64(7, updatedAtMs, BigInt('0'));
}

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


unpack(): EntitlementSnapshotT {
  return new EntitlementSnapshotT(
    this.planCode(),
    this.isPaid(),
    this.source(),
    (this.actor() !== null ? this.actor()!.unpack() : null),
    this.reasonCode(),
    this.startsAtMs(),
    this.endsAtMs(),
    this.updatedAtMs()
  );
}


unpackTo(_o: EntitlementSnapshotT): void {
  _o.planCode = this.planCode();
  _o.isPaid = this.isPaid();
  _o.source = this.source();
  _o.actor = (this.actor() !== null ? this.actor()!.unpack() : null);
  _o.reasonCode = this.reasonCode();
  _o.startsAtMs = this.startsAtMs();
  _o.endsAtMs = this.endsAtMs();
  _o.updatedAtMs = this.updatedAtMs();
}
}

export class EntitlementSnapshotT implements flatbuffers.IGeneratedObject {
constructor(
  public planCode: string|Uint8Array|null = null,
  public isPaid: boolean = false,
  public source: string|Uint8Array|null = null,
  public actor: ActorRefT|null = null,
  public reasonCode: string|Uint8Array|null = null,
  public startsAtMs: bigint = BigInt('0'),
  public endsAtMs: bigint = BigInt('0'),
  public updatedAtMs: bigint = BigInt('0')
){}


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

  EntitlementSnapshot.startEntitlementSnapshot(builder);
  EntitlementSnapshot.addPlanCode(builder, planCode);
  EntitlementSnapshot.addIsPaid(builder, this.isPaid);
  EntitlementSnapshot.addSource(builder, source);
  EntitlementSnapshot.addActor(builder, actor);
  EntitlementSnapshot.addReasonCode(builder, reasonCode);
  EntitlementSnapshot.addStartsAtMs(builder, this.startsAtMs);
  EntitlementSnapshot.addEndsAtMs(builder, this.endsAtMs);
  EntitlementSnapshot.addUpdatedAtMs(builder, this.updatedAtMs);

  return EntitlementSnapshot.endEntitlementSnapshot(builder);
}
}
