package mapped;

import java.util.Iterator;
import java.util.LinkedList;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSWorldMapArea;

@ObfuscatedName("jv")
public class WorldMapArea implements RSWorldMapArea {
   @ObfuscatedName("at")
   @ObfuscatedGetter(
      intValue = 1908118579
   )
   int id;
   @ObfuscatedName("ah")
   String internalName;
   @ObfuscatedName("ar")
   String externalName;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      intValue = 1078124901
   )
   int field2463;
   @ObfuscatedName("ab")
   @ObfuscatedGetter(
      intValue = -1899922447
   )
   int field2466;
   @ObfuscatedName("au")
   @ObfuscatedGetter(
      intValue = 532177377
   )
   int zoom;
   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "Lmh;"
   )
   Coord origin;
   @ObfuscatedName("ac")
   @ObfuscatedGetter(
      intValue = 1218704017
   )
   int regionLowX;
   @ObfuscatedName("al")
   @ObfuscatedGetter(
      intValue = -729106127
   )
   int regionHighX;
   @ObfuscatedName("az")
   @ObfuscatedGetter(
      intValue = -1755160877
   )
   int regionLowY;
   @ObfuscatedName("ap")
   @ObfuscatedGetter(
      intValue = -295283373
   )
   int regionHighY;
   @ObfuscatedName("av")
   boolean isMain;
   @ObfuscatedName("ax")
   LinkedList sections;

   public WorldMapArea() {
      this.id = -1;
      this.field2463 = -1;
      this.field2466 = -16777216;
      this.zoom = -1;
      this.origin = null;
      this.regionLowX = Integer.MAX_VALUE;
      this.regionHighX = 0;
      this.regionLowY = Integer.MAX_VALUE;
      this.regionHighY = 0;
      this.isMain = false;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(Luj;IZI)V",
      garbageValue = "-44094135"
   )
   public void method4547(Buffer var1, int var2, boolean var3) {
      this.id = var2;
      this.internalName = var1.readStringCp1252NullTerminated_base();
      this.externalName = var1.readStringCp1252NullTerminated_base();
      this.origin = new Coord(var1.readInt_base());
      this.field2463 = var1.readInt_base();
      if(var3) {
         this.field2466 = var1.readInt_base();
      }

      var1.readUnsignedByte_base();
      this.isMain = var1.readUnsignedByte_base() == 1;
      this.zoom = var1.readUnsignedByte_base();
      int var4 = var1.readUnsignedByte_base();
      this.sections = new LinkedList();

      for(int var5 = 0; var5 < var4; ++var5) {
         this.sections.add(this.method4601(var1));
      }

      this.setBounds_base();
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Luj;B)Ljj;",
      garbageValue = "2"
   )
   WorldMapSection method4601(Buffer var1) {
      int var2 = var1.readUnsignedByte_base();
      WorldMapSectionType var3 = (WorldMapSectionType)class12.method170(WorldMapSectionType.method4884(), var2);
      Object var4 = null;
      switch(var3.type) {
      case 0:
         var4 = new WorldMapSection2();
         break;
      case 1:
         var4 = new WorldMapSection1();
         break;
      case 2:
         var4 = new class240();
         break;
      case 3:
         var4 = new WorldMapSection0();
         break;
      default:
         throw new IllegalStateException("");
      }

      ((WorldMapSection)var4).vmethod5019(var1);
      return (WorldMapSection)var4;
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(IIII)Z",
      garbageValue = "-1997484864"
   )
   public boolean containsCoord_base(int var1, int var2, int var3) {
      Iterator var4 = this.sections.iterator();

      WorldMapSection var5;
      do {
         if(!var4.hasNext()) {
            return false;
         }

         var5 = (WorldMapSection)var4.next();
      } while(!var5.containsCoord_base(var1, var2, var3));

      return true;
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(IIB)Z",
      garbageValue = "0"
   )
   public boolean containsPosition_base(int var1, int var2) {
      int var3 = var1 / 64;
      int var4 = var2 / 64;
      if(var3 >= this.regionLowX && var3 <= this.regionHighX) {
         if(var4 >= this.regionLowY && var4 <= this.regionHighY) {
            Iterator var5 = this.sections.iterator();

            WorldMapSection var6;
            do {
               if(!var5.hasNext()) {
                  return false;
               }

               var6 = (WorldMapSection)var5.next();
            } while(!var6.containsPosition_base(var1, var2));

            return true;
         } else {
            return false;
         }
      } else {
         return false;
      }
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(IIIB)[I",
      garbageValue = "1"
   )
   public int[] position_base(int var1, int var2, int var3) {
      Iterator var4 = this.sections.iterator();

      WorldMapSection var5;
      do {
         if(!var4.hasNext()) {
            return null;
         }

         var5 = (WorldMapSection)var4.next();
      } while(!var5.containsCoord_base(var1, var2, var3));

      return var5.getBorderTileLengths_base(var1, var2, var3);
   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "(III)Lmh;",
      garbageValue = "-1546561143"
   )
   public Coord method4552(int var1, int var2) {
      Iterator var3 = this.sections.iterator();

      WorldMapSection var4;
      do {
         if(!var3.hasNext()) {
            return null;
         }

         var4 = (WorldMapSection)var3.next();
      } while(!var4.containsPosition_base(var1, var2));

      return var4.vmethod5029(var1, var2);
   }

   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "611139604"
   )
   void setBounds_base() {
      Iterator var1 = this.sections.iterator();

      while(var1.hasNext()) {
         WorldMapSection var2 = (WorldMapSection)var1.next();
         var2.vmethod5026(this);
      }

   }

   @ObfuscatedName("ac")
   @ObfuscatedSignature(
      descriptor = "(B)I",
      garbageValue = "73"
   )
   public int getId_base() {
      return this.id;
   }

   @ObfuscatedName("al")
   @ObfuscatedSignature(
      descriptor = "(I)Z",
      garbageValue = "1014185109"
   )
   public boolean getIsMain_base() {
      return this.isMain;
   }

   @ObfuscatedName("az")
   @ObfuscatedSignature(
      descriptor = "(I)Ljava/lang/String;",
      garbageValue = "1909349089"
   )
   public String getInternalName_base() {
      return this.internalName;
   }

   @ObfuscatedName("ap")
   @ObfuscatedSignature(
      descriptor = "(I)Ljava/lang/String;",
      garbageValue = "-1365317840"
   )
   public String getExternalName_base() {
      return this.externalName;
   }

   @ObfuscatedName("av")
   @ObfuscatedSignature(
      descriptor = "(B)I",
      garbageValue = "33"
   )
   int method4573_base() {
      return this.field2463;
   }

   @ObfuscatedName("ax")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "-1742263057"
   )
   int method4620_base() {
      return this.field2466;
   }

   @ObfuscatedName("as")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "1201387673"
   )
   public int getZoom_base() {
      return this.zoom;
   }

   @ObfuscatedName("ay")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "-1807979529"
   )
   public int getRegionLowX_base() {
      return this.regionLowX;
   }

   @ObfuscatedName("ak")
   @ObfuscatedSignature(
      descriptor = "(B)I",
      garbageValue = "23"
   )
   public int getRegionHighX_base() {
      return this.regionHighX;
   }

   @ObfuscatedName("aj")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "-2107493604"
   )
   public int getRegionLowY_base() {
      return this.regionLowY;
   }

   @ObfuscatedName("am")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "1685768415"
   )
   public int getRegionHighY_base() {
      return this.regionHighY;
   }

   @ObfuscatedName("aq")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "494271544"
   )
   public int getOriginX_base() {
      return this.origin.x;
   }

   @ObfuscatedName("ai")
   @ObfuscatedSignature(
      descriptor = "(S)I",
      garbageValue = "-2282"
   )
   public int getOriginPlane_base() {
      return this.origin.plane;
   }

   @ObfuscatedName("aw")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "927085335"
   )
   public int getOriginY_base() {
      return this.origin.y;
   }

   @ObfuscatedName("ae")
   @ObfuscatedSignature(
      descriptor = "(B)Lmh;",
      garbageValue = "-69"
   )
   public Coord method4567() {
      return new Coord(this.origin);
   }

   public boolean surfaceContainsPosition(int var1, int var2) {
      return this.containsPosition_base(var1, var2);
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(CB)Z",
      garbageValue = "-71"
   )
   public static boolean method4577_base(char var0) {
      if((var0 <= 0 || var0 >= 128) && (var0 < 160 || var0 > 255)) {
         if(var0 != 0) {
            char[] var1 = class396.cp1252AsciiExtension;

            for(int var2 = 0; var2 < var1.length; ++var2) {
               char var3 = var1[var2];
               if(var0 == var3) {
                  return true;
               }
            }
         }

         return false;
      } else {
         return true;
      }
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(II)Lun;",
      garbageValue = "-1672092553"
   )
   public static PrivateChatMode method4580(int var0) {
      PrivateChatMode[] var1 = SecureRandomCallable.method2319();

      for(int var2 = 0; var2 < var1.length; ++var2) {
         PrivateChatMode var3 = var1[var2];
         if(var0 == var3.field5279) {
            return var3;
         }
      }

      return null;
   }

   @ObfuscatedName("al")
   @ObfuscatedSignature(
      descriptor = "(Ljava/lang/String;B)V",
      garbageValue = "122"
   )
   static final void method4622_base(String var0) {
      GrandExchangeOfferUnitPriceComparator.addGameMessage_base(30, "", var0);
   }

   @ObfuscatedName("az")
   @ObfuscatedSignature(
      descriptor = "([BB)Lpf;",
      garbageValue = "53"
   )
   public static Font method4590(byte[] var0) {
      if(var0 == null) {
         return null;
      } else {
         Font var1 = new Font(var0, class541.SpriteBuffer_xOffsets, class541.SpriteBuffer_yOffsets, class541.SpriteBuffer_spriteWidths, class520.SpriteBuffer_spriteHeights, class541.SpriteBuffer_spritePalette, class396.SpriteBuffer_pixels);
         class458.method8401_base();
         return var1;
      }
   }
}
