package mapped;

import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Shape;
import net.runelite.api.Perspective;
import net.runelite.api.Point;
import net.runelite.api.TileObject;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.geometry.Shapes;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSBoundaryObject;
import net.runelite.rs.api.RSGameObject;
import net.runelite.rs.api.RSModel;
import net.runelite.rs.api.RSRenderable;

@ObfuscatedName("lv")
public final class BoundaryObject implements RSBoundaryObject, TileObject {
   @ObfuscatedName("at")
   @ObfuscatedGetter(
      intValue = -1482924971
   )
   int z;
   @ObfuscatedName("ah")
   @ObfuscatedGetter(
      intValue = 318449937
   )
   int x;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = 1236392233
   )
   int y;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      intValue = -2084743841
   )
   int orientationA;
   @ObfuscatedName("ab")
   @ObfuscatedGetter(
      intValue = -1282783987
   )
   int orientationB;
   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "Lkt;"
   )
   public Renderable renderable1;
   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "Lkt;"
   )
   public Renderable renderable2;
   @ObfuscatedName("ac")
   @ObfuscatedGetter(
      longValue = 1522233317223914197L
   )
   public long tag;
   @ObfuscatedName("al")
   @ObfuscatedGetter(
      intValue = 1298806641
   )
   int flags;
   public int wallPlane;

   BoundaryObject() {
      this.tag = 0L;
      this.flags = 0;
   }

   public Point getCanvasLocation(int var1) {
      return Perspective.localToCanvas(SpriteMask.client, this.getLocalLocation(), this.getPlane(), var1);
   }

   public RSModel getModelA() {
      RSRenderable var1 = this.getRenderable1();
      return var1 == null?null:(var1 instanceof net.runelite.api.Model?(RSModel)var1:var1.getModel());
   }

   public RSModel getModelB() {
      RSRenderable var1 = this.getRenderable2();
      return var1 == null?null:(var1 instanceof net.runelite.api.Model?(RSModel)var1:var1.getModel());
   }

   public long getHash() {
      return this.tag;
   }

   public RSRenderable getRenderable1() {
      return this.renderable1;
   }

   public RSRenderable getRenderable2() {
      return this.renderable2;
   }

   public int getX() {
      return this.x;
   }

   public int getId() {
      long var1 = this.getHash();
      return (int)(var1 >>> 17 & 4294967295L);
   }

   public LocalPoint getLocalLocation() {
      return new LocalPoint(this.getX(), this.getY());
   }

   public int getY() {
      return this.y;
   }

   public int getPlane() {
      return this.wallPlane;
   }

   public int getZ() {
      return this.z;
   }

   public void setPlane(int var1) {
      this.wallPlane = var1;
   }

   public Shape getClickbox() {
      Shape var1 = Perspective.getClickbox(SpriteMask.client, this.getModelA(), 0, this.getX(), this.getY(), this.getZ());
      Shape var2 = Perspective.getClickbox(SpriteMask.client, this.getModelB(), 0, this.getX(), this.getY(), this.getZ());
      return (Shape)(var1 == null && var2 == null?null:(var1 != null && var2 != null?new Shapes(new Shape[]{var1, var2}):(var1 != null?var1:var2)));
   }

   public Shape getConvexHull() {
      RSModel var1 = this.getModelA();
      if(var1 == null) {
         return null;
      } else {
         int var2 = Perspective.getTileHeight(SpriteMask.client, new LocalPoint(this.getX(), this.getY()), SpriteMask.client.getPlane());
         return var1.getConvexHull(this.getX(), this.getY(), 0, var2);
      }
   }

   public Shape getConvexHull2() {
      RSModel var1 = this.getModelB();
      if(var1 == null) {
         return null;
      } else {
         int var2 = Perspective.getTileHeight(SpriteMask.client, new LocalPoint(this.getX(), this.getY()), SpriteMask.client.getPlane());
         return var1.getConvexHull(this.getX(), this.getY(), 0, var2);
      }
   }

   public String getName() {
      return SpriteMask.client.getObjectDefinition(this.getId()).getName();
   }

   public String[] getActions() {
      return SpriteMask.client.getObjectDefinition(this.getId()).getActions();
   }

   public WorldPoint getWorldLocation() {
      return WorldPoint.fromLocal(SpriteMask.client, this.getX(), this.getY(), this.getPlane());
   }

   public Point getCanvasLocation() {
      return this.getCanvasLocation(0);
   }

   public Polygon getCanvasTilePoly() {
      int var1 = 1;
      int var2 = 1;

      return Perspective.getCanvasTileAreaPoly(SpriteMask.client, this.getLocalLocation(), var1, var2, this.getPlane(), 0);
   }

   public Point getCanvasTextLocation(Graphics2D var1, String var2, int var3) {
      return Perspective.getCanvasTextLocation(SpriteMask.client, var1, this.getLocalLocation(), var2, var3);
   }

   public Point getMinimapLocation() {
      return Perspective.localToMinimap(SpriteMask.client, this.getLocalLocation());
   }

   public int getOrientationA() {
      return this.orientationA;
   }

   public int getOrientationB() {
      return this.orientationB;
   }

   public int getConfig() {
      return this.flags;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "([Ljava/lang/CharSequence;III)Ljava/lang/String;",
      garbageValue = "-1198617474"
   )
   public static String method5819_base(CharSequence[] var0, int var1, int var2) {
      if(var2 == 0) {
         return "";
      } else if(var2 == 1) {
         CharSequence var3 = var0[var1];
         return var3 == null?"null":var3.toString();
      } else {
         int var8 = var2 + var1;
         int var4 = 0;

         for(int var5 = var1; var5 < var8; ++var5) {
            CharSequence var6 = var0[var5];
            if(var6 == null) {
               var4 += 4;
            } else {
               var4 += var6.length();
            }
         }

         StringBuilder var9 = new StringBuilder(var4);

         for(int var10 = var1; var10 < var8; ++var10) {
            CharSequence var7 = var0[var10];
            if(var7 == null) {
               var9.append("null");
            } else {
               var9.append(var7);
            }
         }

         return var9.toString();
      }
   }
}
