package mapped;

import net.runelite.api.IterableHashTable;
import net.runelite.api.ParamHolder;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSIntegerNode;
import net.runelite.rs.api.RSIterableNodeHashTable;
import net.runelite.rs.api.RSNode;
import net.runelite.rs.api.RSObjectNode;
import net.runelite.rs.api.RSParamComposition;
import net.runelite.rs.api.RSStructComposition;

@ObfuscatedName("hy")
public class StructComposition extends DualNode implements RSStructComposition, ParamHolder {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lol;"
   )
   static AbstractArchive StructDefinition_archive;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Llk;"
   )
   static EvictingDualNodeHashTable StructDefinition_cached;
   @ObfuscatedName("fn")
   @ObfuscatedSignature(
      descriptor = "Loh;"
   )
   static Archive field2041;
   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "Ltz;"
   )
   IterableNodeHashTable params;
   @ObfuscatedName("id")
   public int field2049;

   static {
      StructDefinition_cached = new EvictingDualNodeHashTable(64);
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-968582789"
   )
   void postDecode_base() {
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(Luj;I)V",
      garbageValue = "-1850200983"
   )
   void method3850(Buffer var1) {
      while(true) {
         int var2 = var1.readUnsignedByte_base();
         if(var2 == 0) {
            return;
         }

         this.method3834(var1, var2);
      }
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(Luj;IB)V",
      garbageValue = "4"
   )
   void method3834(Buffer var1, int var2) {
      if(var2 == 249) {
         this.params = class144.method3229(var1, this.params);
      }

   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "(III)I",
      garbageValue = "-408803352"
   )
   public int getIntParam_base(int var1, int var2) {
      return Player.method2444(this.params, var1, var2);
   }

   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "(ILjava/lang/String;B)Ljava/lang/String;",
      garbageValue = "78"
   )
   public String getStringParam_base(int var1, String var2) {
      IterableNodeHashTable var4 = this.params;
      String var3;
      if(var4 == null) {
         var3 = var2;
      } else {
         ObjectNode var5 = (ObjectNode)var4.get((long)var1);
         if(var5 == null) {
            var3 = var2;
         } else {
            var3 = (String)var5.obj;
         }
      }

      return var3;
   }

   public RSNode getParam(int var1) {
      return this.getParams() == null?null:(RSNode)this.getParams().get((long)var1);
   }

   public void setParam(int var1, RSNode var2) {
      RSParamComposition var3 = SpriteMask.client.getRSParamComposition(var1);
      if(var3.isString() != (var2 instanceof RSObjectNode)) {
         if(var3.isString()) {
            throw new IllegalArgumentException("trying to put int into string param");
         } else {
            throw new IllegalArgumentException("trying to put string into int param");
         }
      } else {
         if(this.getParams() == null) {
            this.setParams((IterableHashTable)SpriteMask.client.newIterableNodeHashTable(16));
         }

         this.getParams().put(var2, (long)var1);
      }
   }

   public void setParams(IterableHashTable var1) {
      this.params = (IterableNodeHashTable)var1;
   }

   public int getIntValue(int var1) {
      RSNode var2 = this.getParam(var1);
      if(var2 != null) {
         RSIntegerNode var4 = (RSIntegerNode)var2;
         return var4.getValue();
      } else {
         RSParamComposition var3 = SpriteMask.client.getRSParamComposition(var1);
         if(var3.isString()) {
            throw new IllegalArgumentException("trying to get int from string param");
         } else {
            return var3.getDefaultInt();
         }
      }
   }

   public void setValue(int var1, int var2) {
      this.setParam(var1, SpriteMask.client.newIntegerNode(var2));
   }

   public String getStringValue(int var1) {
      RSNode var2 = this.getParam(var1);
      if(var2 != null) {
         RSObjectNode var4 = (RSObjectNode)var2;
         return (String)var4.getValue();
      } else {
         RSParamComposition var3 = SpriteMask.client.getRSParamComposition(var1);
         if(!var3.isString()) {
            throw new IllegalArgumentException("trying to get string from int param");
         } else {
            return var3.getDefaultStr();
         }
      }
   }

   public void setValue(int var1, String var2) {
      this.setParam(var1, SpriteMask.client.newObjectNode(var2));
   }

   public int getId() {
      return this.field2049;
   }

   public void setId(int var1) {
      this.field2049 = var1;
   }

   public RSIterableNodeHashTable getParams() {
      return this.params;
   }

   public void setParams(RSIterableNodeHashTable var1) {
      this.params = (IterableNodeHashTable)var1;
   }
}
