package mapped;

import net.runelite.api.Deque;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSFriendsList;

@ObfuscatedName("qh")
public class FriendsList extends UserList<net.runelite.api.Friend> implements RSFriendsList {
   @ObfuscatedName("ay")
   @ObfuscatedSignature(
      descriptor = "Lup;"
   )
   static IndexedSprite options_buttons_2Sprite;
   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "Ltt;"
   )
   final LoginType loginType;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      intValue = 1422040949
   )
   int field4666;
   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "Lpu;"
   )
   public LinkDeque friendLoginUpdates;

   @ObfuscatedSignature(
      descriptor = "(Ltt;)V"
   )
   public FriendsList(LoginType var1) {
      super(400);
      this.field4666 = 1;
      this.friendLoginUpdates = new LinkDeque();
      this.loginType = var1;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(I)Lrf;",
      garbageValue = "794695059"
   )
   User vmethod8212() {
      return new Friend();
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(II)[Lrf;",
      garbageValue = "-190310061"
   )
   User[] vmethod8221(int var1) {
      return new Friend[var1];
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(Lvj;ZI)Z",
      garbageValue = "645872851"
   )
   public boolean method8075(Username var1, boolean var2) {
      Friend var3 = (Friend)this.method8185(var1);
      return var3 == null?false:!var2 || var3.world != 0;
   }

   @ObfuscatedName("al")
   @ObfuscatedSignature(
      descriptor = "(Luj;II)V",
      garbageValue = "-846480965"
   )
   public void method8079(Buffer var1, int var2) {
      while(true) {
         if(var1.offset < var2) {
            boolean var3 = var1.readUnsignedByte_base() == 1;
            Username var4 = new Username(var1.readStringCp1252NullTerminated_base(), this.loginType);
            Username var5 = new Username(var1.readStringCp1252NullTerminated_base(), this.loginType);
            int var6 = var1.readUnsignedShort_base();
            int var7 = var1.readUnsignedByte_base();
            int var8 = var1.readUnsignedByte_base();
            boolean var9 = (var8 & 2) != 0;
            boolean var10 = (var8 & 1) != 0;
            if(var6 > 0) {
               var1.readStringCp1252NullTerminated_base();
               var1.readUnsignedByte_base();
               var1.readInt_base();
            }

            var1.readStringCp1252NullTerminated_base();
            if(var4 != null && var4.hasCleanName_base()) {
               Friend var11 = (Friend)this.method8222(var4);
               if(var3) {
                  Friend var12 = (Friend)this.method8222(var5);
                  if(var12 != null && var11 != var12) {
                     if(var11 != null) {
                        this.method8189(var12);
                     } else {
                        var11 = var12;
                     }
                  }
               }

               if(var11 != null) {
                  this.method8194(var11, var4, var5);
                  if(var6 != var11.world) {
                     boolean var14 = true;

                     for(FriendLoginUpdate var13 = (FriendLoginUpdate)this.friendLoginUpdates.method7364(); var13 != null; var13 = (FriendLoginUpdate)this.friendLoginUpdates.method7362()) {
                        if(var13.username.equals(var4)) {
                           if(var6 != 0 && var13.world == 0) {
                              var13.remove_base();
                              var14 = false;
                           } else if(var6 == 0 && var13.world != 0) {
                              var13.remove_base();
                              var14 = false;
                           }
                        }
                     }

                     if(var14) {
                        this.friendLoginUpdates.method7365(new FriendLoginUpdate(var4, var6));
                     }
                  }
               } else {
                  if(this.getSize_base() >= 400) {
                     continue;
                  }

                  var11 = (Friend)this.method8191(var4, var5);
               }

               if(var6 != var11.world) {
                  var11.int2 = ++this.field4666 - 1;
                  if(var11.world == -1 && var6 == 0) {
                     var11.int2 = -(var11.int2 * 1393374135) * -977987065;
                  }

                  var11.world = var6;
               }

               var11.rank = var7;
               var11.field4681 = var9;
               var11.field4679 = var10;
               continue;
            }

            throw new IllegalStateException();
         }

         this.sort_base();
         return;
      }
   }

   public Deque getPendingLogins() {
      return this.friendLoginUpdates;
   }
}
