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.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSFloorDecoration;
import net.runelite.rs.api.RSGameObject;
import net.runelite.rs.api.RSModel;
import net.runelite.rs.api.RSRenderable;

@ObfuscatedName("km")
public final class FloorDecoration implements RSFloorDecoration, TileObject {
   @ObfuscatedName("aa")
   @ObfuscatedGetter(
      intValue = -1764906591
   )
   static int field2713;
   @ObfuscatedName("at")
   @ObfuscatedGetter(
      intValue = 1858852897
   )
   int z;
   @ObfuscatedName("ah")
   @ObfuscatedGetter(
      intValue = 1647703591
   )
   int x;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = -880112075
   )
   int y;
   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "Lkt;"
   )
   public Renderable renderable;
   @ObfuscatedName("ab")
   @ObfuscatedGetter(
      longValue = 2857987176138791039L
   )
   public long tag;
   @ObfuscatedName("au")
   @ObfuscatedGetter(
      intValue = 342494541
   )
   int flags;
   public int groundObjectPlane;

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

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

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

   public RSRenderable getRenderable() {
      return this.renderable;
   }

   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.groundObjectPlane;
   }

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

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

   public Shape getConvexHull() {
      RSModel var1 = this.getModel();
      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 getClickbox() {
      return Perspective.getClickbox(SpriteMask.client, this.getModel(), 0, this.getX(), this.getY(), this.getZ());
   }

   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 getConfig() {
      return this.flags;
   }
}
