package mapped;

import java.util.function.Consumer;
import net.runelite.api.MenuEntry;
import net.runelite.mapping.Export;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.rs.api.RSNPC;
import net.runelite.rs.api.RSPlayer;
import net.runelite.rs.api.RSRuneLiteMenuEntry;

public class RuneLiteMenuEntry implements MenuEntry, RSRuneLiteMenuEntry {
   @Export("idx")
   @ObfuscatedName("idx")
   public int field5307;
   @Export("parent")
   private MenuEntry parent;
   @Export("consumer")
   public Consumer consumer;

   public RuneLiteMenuEntry() {
      this.field5307 = 499;
   }

   public RuneLiteMenuEntry(int var1) {
      this.field5307 = var1;
   }

   @Export("setParam0")
   public MenuEntry setParam0(int var1) {
      Client.menuArguments1[this.field5307] = var1;
      return this;
   }

   @Export("setParam1")
   public MenuEntry setParam1(int var1) {
      Client.menuArguments2[this.field5307] = var1;
      return this;
   }

   @Export("getNpc")
   public net.runelite.api.NPC getNpc() {
      RSNPC[] var1 = SpriteMask.client.getCachedNPCs();
      RSNPC var2 = null;
      net.runelite.api.MenuAction var3 = this.getType();
      if(var3 == net.runelite.api.MenuAction.NPC_FIRST_OPTION || var3 == net.runelite.api.MenuAction.NPC_SECOND_OPTION || var3 == net.runelite.api.MenuAction.NPC_THIRD_OPTION || var3 == net.runelite.api.MenuAction.NPC_FOURTH_OPTION || var3 == net.runelite.api.MenuAction.NPC_FIFTH_OPTION || var3 == net.runelite.api.MenuAction.WIDGET_TARGET_ON_NPC || var3 == net.runelite.api.MenuAction.EXAMINE_NPC) {
         int var4 = this.getIdentifier();
         if(var4 >= 0 && var4 < var1.length) {
            var2 = var1[var4];
         }
      }

      return var2;
   }

   @Export("getParam0")
   public int getParam0() {
      return Client.menuArguments1[this.field5307];
   }

   @Export("getParam1")
   public int getParam1() {
      return Client.menuArguments2[this.field5307];
   }

   @Export("getType")
   public net.runelite.api.MenuAction getType() {
      int var1 = Client.menuOpcodes[this.field5307];
      if(var1 >= 2000) {
         var1 -= 2000;
      }

      return net.runelite.api.MenuAction.of(var1);
   }

   @Export("getIdentifier")
   public int getIdentifier() {
      return Client.menuIdentifiers[this.field5307];
   }

   @Export("instanceOf")
   public boolean instanceOf(Object var1) {
      return var1 instanceof RuneLiteMenuEntry;
   }

   @Export("getOption")
   public String getOption() {
      return Client.menuActions[this.field5307];
   }

   @Export("getPlayer")
   public net.runelite.api.Player getPlayer() {
      RSPlayer[] var1 = SpriteMask.client.getCachedPlayers();
      RSPlayer var2 = null;
      net.runelite.api.MenuAction var3 = this.getType();
      if(var3 == net.runelite.api.MenuAction.PLAYER_FIRST_OPTION || var3 == net.runelite.api.MenuAction.PLAYER_SECOND_OPTION || var3 == net.runelite.api.MenuAction.PLAYER_THIRD_OPTION || var3 == net.runelite.api.MenuAction.PLAYER_FOURTH_OPTION || var3 == net.runelite.api.MenuAction.PLAYER_FIFTH_OPTION || var3 == net.runelite.api.MenuAction.PLAYER_SIXTH_OPTION || var3 == net.runelite.api.MenuAction.PLAYER_SEVENTH_OPTION || var3 == net.runelite.api.MenuAction.PLAYER_EIGHTH_OPTION || var3 == net.runelite.api.MenuAction.WIDGET_TARGET_ON_PLAYER || var3 == net.runelite.api.MenuAction.RUNELITE_PLAYER) {
         int var4 = this.getIdentifier();
         if(var4 >= 0 && var4 < var1.length) {
            var2 = var1[var4];
         }
      }

      return var2;
   }

   @Export("getTarget")
   public String getTarget() {
      return Client.menuTargets[this.field5307];
   }

   @Export("getItemId")
   public int getItemId() {
      return Client.menuItemIds[this.field5307];
   }

   @Export("isForceLeftClick")
   public boolean isForceLeftClick() {
      return Client.menuShiftClick[this.field5307];
   }

   @Export("isDeprioritized")
   public boolean isDeprioritized() {
      return Client.menuOpcodes[this.field5307] >= 2000;
   }

   @Export("getConsumer")
   public Consumer getConsumer() {
      return this.consumer;
   }

   @Export("setConsumer")
   public void setConsumer(Consumer var1) {
      this.consumer = var1;
   }

   @Export("getIdx")
   public int getIdx() {
      return this.field5307;
   }

   @Export("setIdx")
   public void setIdx(int var1) {
      this.field5307 = var1;
   }

   @Export("setOption")
   public MenuEntry setOption(String var1) {
      Client.menuActions[this.field5307] = var1;
      return this;
   }

   @Export("setTarget")
   public MenuEntry setTarget(String var1) {
      Client.menuTargets[this.field5307] = var1;
      return this;
   }

   @Export("getMenuAction")
   public net.runelite.api.MenuAction getMenuAction() {
      return this.getType();
   }

   @Export("setType")
   public MenuEntry setType(net.runelite.api.MenuAction var1) {
      int var2 = Client.menuOpcodes[this.field5307];
      short var3 = 0;
      if(var2 >= 2000) {
         var3 = 2000;
      }

      Client.menuOpcodes[this.field5307] = var1.getId() + var3;
      return this;
   }

   @Export("getOpcode")
   public int getOpcode() {
      int var1 = Client.menuOpcodes[this.field5307];
      if(var1 >= 2000) {
         var1 -= 2000;
      }

      return var1;
   }

   @Export("setOpcode")
   public void setOpcode(int var1) {
      int var2 = Client.menuOpcodes[this.field5307];
      short var3 = 0;
      if(var2 >= 2000) {
         var3 = 2000;
      }

      Client.menuOpcodes[this.field5307] = var3 + var1;
   }

   @Export("setIdentifier")
   public MenuEntry setIdentifier(int var1) {
      Client.menuIdentifiers[this.field5307] = var1;
      return this;
   }

   @Export("getActionParam0")
   public int getActionParam0() {
      return this.getParam0();
   }

   @Export("setActionParam0")
   public void setActionParam0(int var1) {
      this.setParam0(var1);
   }

   @Export("getActionParam1")
   public int getActionParam1() {
      return this.getParam1();
   }

   @Export("setActionParam1")
   public void setActionParam1(int var1) {
      this.setParam1(var1);
   }

   @Export("setDeprioritized")
   public MenuEntry setDeprioritized(boolean var1) {
      int[] var2;
      if(var1) {
         if(Client.menuOpcodes[this.field5307] < 2000) {
            var2 = Client.menuOpcodes;
            var2[this.field5307] += 2000;
         }
      } else if(Client.menuOpcodes[this.field5307] >= 2000) {
         var2 = Client.menuOpcodes;
         var2[this.field5307] -= 2000;
      }

      return this;
   }

   @Export("setParent")
   public MenuEntry setParent(MenuEntry var1) {
      if(this == var1) {
         throw new IllegalArgumentException("cannot set parent to self");
      } else {
         SpriteMask.client.getMenuEntries()[this.field5307] = var1;
         return this;
      }
   }

   @Export("getParent")
   public MenuEntry getParent() {
      return this.parent;
   }

   @Export("setForceLeftClick")
   public MenuEntry setForceLeftClick(boolean var1) {
      Client.menuShiftClick[this.field5307] = var1;
      return this;
   }

   @Export("onClick")
   public MenuEntry onClick(Consumer var1) {
      this.consumer = var1;
      return this;
   }

   @Export("equals")
   public boolean equals(Object var1) {
      if(this == var1) {
         return true;
      } else if(!(var1 instanceof RuneLiteMenuEntry)) {
         return false;
      } else {
         RuneLiteMenuEntry var2 = (RuneLiteMenuEntry)var1;
         if(!var2.instanceOf(this)) {
            return false;
         } else if(this.getIdentifier() != var2.getIdentifier()) {
            return false;
         } else if(this.getParam0() != var2.getParam0()) {
            return false;
         } else if(this.getParam1() != var2.getParam1()) {
            return false;
         } else if(this.getItemId() != var2.getItemId()) {
            return false;
         } else if(this.isForceLeftClick() != var2.isForceLeftClick()) {
            return false;
         } else if(this.isDeprioritized() != var2.isDeprioritized()) {
            return false;
         } else {
            String var3 = this.getOption();
            String var4 = var2.getOption();
            if(var3 == null) {
               if(var4 != null) {
                  return false;
               }
            } else if(!var3.equals(var4)) {
               return false;
            }

            String var5 = this.getTarget();
            String var6 = var2.getTarget();
            if(var5 == null) {
               if(var6 != null) {
                  return false;
               }
            } else if(!var5.equals(var6)) {
               net.runelite.api.MenuAction var7 = this.getType();
               net.runelite.api.MenuAction var8 = var2.getType();
               if(var7 == null) {
                  if(var8 == null) {
                     return true;
                  }
               } else if(var7.equals(var8)) {
                  return true;
               }

               return false;
            }

            return false;
         }
      }
   }

   @Export("isItemOp")
   public boolean isItemOp() {
      net.runelite.api.MenuAction var1 = this.getType();
      if(var1 == net.runelite.api.MenuAction.CC_OP || var1 == net.runelite.api.MenuAction.CC_OP_LOW_PRIORITY) {
         int var2 = this.getIdentifier();
         int var3 = this.getParam1();
         if(var3 == 9764864) {
            switch(var2) {
            case 1:
            case 2:
            case 3:
            case 4:
            case 6:
            case 7:
               return true;
            case 5:
            }
         }
      }

      return false;
   }

   @Export("getItemOp")
   public int getItemOp() {
      net.runelite.api.MenuAction var1 = this.getType();
      if(var1 == net.runelite.api.MenuAction.CC_OP || var1 == net.runelite.api.MenuAction.CC_OP_LOW_PRIORITY) {
         int var2 = this.getIdentifier();
         int var3 = this.getParam0();
         int var4 = this.getParam1();
         if(var4 == 9764864) {
            switch(var2) {
            case 1:
               net.runelite.api.widgets.Widget var5 = SpriteMask.client.getWidget(var4);
               if(var5 != null && var3 != -1) {
                  var5 = var5.getChild(var3);
                  if(var5 != null && var5.getItemId() > -1) {
                     int var6 = SpriteMask.client.getItemComposition(var5.getItemId()).getShiftClickActionIndex();
                     if(var6 >= 0) {
                        return var6 + 1;
                     }
                  }
               }
               break;
            case 2:
               return 1;
            case 3:
               return 2;
            case 4:
               return 3;
            case 5:
            default:
               break;
            case 6:
               return 4;
            case 7:
               return 5;
            }
         }
      }

      return -1;
   }

   @Export("setItemId")
   public void setItemId(int var1) {
      Client.menuItemIds[this.field5307] = var1;
   }

   @Export("getWidget")
   public net.runelite.api.widgets.Widget getWidget() {
      int var1 = this.getParam1();
      int var2 = this.getParam0();
      net.runelite.api.widgets.Widget var3 = SpriteMask.client.getWidget(var1);
      if(var3 == null) {
         return null;
      } else {
         if(var2 != -1) {
            net.runelite.api.widgets.Widget var4 = var3.getChild(var2);
            if(var4 != null) {
               return var4;
            }
         }

         return var3;
      }
   }

   @Export("getActor")
   public net.runelite.api.Actor getActor() {
      net.runelite.api.NPC var1 = this.getNpc();
      if(var1 != null) {
         return var1;
      } else {
         net.runelite.api.Player var2 = this.getPlayer();
         return var2 != null?var2:null;
      }
   }

   @Export("hashCode")
   public int hashCode() {
      byte var1 = 1;
      int var2 = var1 * 59 + this.getIdentifier();
      var2 = var2 * 59 + this.getParam0();
      var2 = var2 * 59 + this.getParam1();
      var2 = var2 * 59 + this.getItemId();
      var2 = var2 * 59 + (this.isForceLeftClick()?79:97);
      var2 = var2 * 59 + (this.isDeprioritized()?79:97);
      String var3 = this.getOption();
      var2 = var2 * 59 + (var3 == null?43:var3.hashCode());
      String var4 = this.getTarget();
      var2 = var2 * 59 + (var4 == null?43:var4.hashCode());
      net.runelite.api.MenuAction var5 = this.getType();
      var2 = var2 * 59 + (var5 == null?43:var5.hashCode());
      return var2;
   }

   @Export("toString")
   public String toString() {
      return "MenuEntryImpl(getOption=" + this.getOption() + ", getTarget=" + this.getTarget() + ", getIdentifier=" + this.getIdentifier() + ", getType=" + this.getType() + ", getParam0=" + this.getParam0() + ", getParam1=" + this.getParam1() + ", getItemId=" + this.getItemId() + ", isForceLeftClick=" + this.isForceLeftClick() + ", isDeprioritized=" + this.isDeprioritized() + ")";
   }
}
