package mapped;

import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSDbRowType;

@ObfuscatedName("tf")
public class DbRowType extends DualNode implements RSDbRowType {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lol;"
   )
   public static AbstractArchive field5085;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Llk;"
   )
   static EvictingDualNodeHashTable DBRowType_cache;
   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "Lol;"
   )
   public static AbstractArchive ItemDefinition_archive;
   @ObfuscatedName("ar")
   Object[][] columnTypes;
   @ObfuscatedName("ao")
   int[][] field5082;
   @ObfuscatedName("ab")
   @ObfuscatedGetter(
      intValue = -1891158047
   )
   public int tableId;

   static {
      DBRowType_cache = new EvictingDualNodeHashTable(64);
   }

   DbRowType() {
      this.tableId = -1;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Luj;S)V",
      garbageValue = "2044"
   )
   void method9182(Buffer var1) {
      while(true) {
         int var2 = var1.readUnsignedByte_base();
         if(var2 == 0) {
            return;
         }

         this.method9170(var1, var2);
      }
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(IB)[Ljava/lang/Object;",
      garbageValue = "14"
   )
   public Object[] getColumnType_base(int var1) {
      return this.columnTypes == null?null:this.columnTypes[var1];
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(Luj;IB)V",
      garbageValue = "55"
   )
   void method9170(Buffer var1, int var2) {
      if(var2 == 3) {
         int var3 = var1.readUnsignedByte_base();
         if(this.columnTypes == null) {
            this.columnTypes = new Object[var3][];
            this.field5082 = new int[var3][];
         }

         for(int var4 = var1.readUnsignedByte_base(); var4 != 255; var4 = var1.readUnsignedByte_base()) {
            int var5 = var1.readUnsignedByte_base();
            int[] var6 = new int[var5];

            for(int var7 = 0; var7 < var5; ++var7) {
               var6[var7] = var1.readUShortSmart_base();
            }

            Object[][] var16 = this.columnTypes;
            int var10 = var1.readUShortSmart_base();
            Object[] var11 = new Object[var6.length * var10];

            for(int var12 = 0; var12 < var10; ++var12) {
               for(int var13 = 0; var13 < var6.length; ++var13) {
                  int var14 = var13 + var6.length * var12;
                  class514 var15 = class472.method8562_base(var6[var13]);
                  var11[var14] = var15.method9126(var1);
               }
            }

            var16[var4] = var11;
            this.field5082[var4] = var6;
         }
      } else if(var2 == 4) {
         this.tableId = var1.packBytesToInt_base();
      }

   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-1202767644"
   )
   void method9165_base() {
   }

   public int getTableId() {
      return this.tableId;
   }

   public Object[] getColumnType(int var1) {
      return this.getColumnType_base(var1);
   }
}
