package mapped;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import net.runelite.api.Nameable;
import net.runelite.api.events.PostStructComposition;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSUser;
import net.runelite.rs.api.RSUserList;
import net.runelite.rs.api.RSUsername;

@ObfuscatedName("rc")
public abstract class UserList<T extends Nameable> implements RSUserList<T> {
   @ObfuscatedName("al")
   @ObfuscatedGetter(
      intValue = -1878565521
   )
   final int capacity;
   @ObfuscatedName("az")
   @ObfuscatedGetter(
      intValue = 1107277597
   )
   int size;
   @ObfuscatedName("ap")
   @ObfuscatedSignature(
      descriptor = "[Lrf;"
   )
   User[] array;
   @ObfuscatedName("av")
   HashMap usernamesMap;
   @ObfuscatedName("ax")
   HashMap previousUsernamesMap;
   @ObfuscatedName("as")
   Comparator comparator;

   UserList(int var1) {
      this.size = 0;
      this.comparator = null;
      this.capacity = var1;
      this.array = this.vmethod8221(var1);
      this.usernamesMap = new HashMap(var1 / 8);
      this.previousUsernamesMap = new HashMap(var1 / 8);
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(I)Lrf;",
      garbageValue = "794695059"
   )
   abstract User vmethod8212();

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(II)[Lrf;",
      garbageValue = "-190310061"
   )
   abstract User[] vmethod8221(int var1);

   @ObfuscatedName("bf")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "-1535217845"
   )
   public void clear_base() {
      this.size = 0;
      Arrays.fill(this.array, (Object)null);
      this.usernamesMap.clear();
      this.previousUsernamesMap.clear();
   }

   @ObfuscatedName("bg")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "-1124880837"
   )
   public int getSize_base() {
      return this.size;
   }

   @ObfuscatedName("ba")
   @ObfuscatedSignature(
      descriptor = "(I)Z",
      garbageValue = "458796278"
   )
   public boolean isFull_base() {
      return this.capacity == this.size;
   }

   @ObfuscatedName("bm")
   @ObfuscatedSignature(
      descriptor = "(Lvj;S)Z",
      garbageValue = "18697"
   )
   public boolean method8182(Username var1) {
      return !var1.hasCleanName_base()?false:(this.usernamesMap.containsKey(var1)?true:this.previousUsernamesMap.containsKey(var1));
   }

   @ObfuscatedName("bp")
   @ObfuscatedSignature(
      descriptor = "(Lvj;I)Lrf;",
      garbageValue = "-1933118786"
   )
   public User method8185(Username var1) {
      User var2 = this.method8222(var1);
      return var2 != null?var2:this.method8187(var1);
   }

   @ObfuscatedName("bw")
   @ObfuscatedSignature(
      descriptor = "(Lvj;I)Lrf;",
      garbageValue = "-1654075733"
   )
   User method8222(Username var1) {
      return !var1.hasCleanName_base()?null:(User)this.usernamesMap.get(var1);
   }

   @ObfuscatedName("bj")
   @ObfuscatedSignature(
      descriptor = "(Lvj;I)Lrf;",
      garbageValue = "-858632406"
   )
   User method8187(Username var1) {
      return !var1.hasCleanName_base()?null:(User)this.previousUsernamesMap.get(var1);
   }

   @ObfuscatedName("bn")
   @ObfuscatedSignature(
      descriptor = "(Lvj;I)Z",
      garbageValue = "193250874"
   )
   public final boolean method8188(Username var1) {
      User var2 = this.method8222(var1);
      if(var2 == null) {
         return false;
      } else {
         this.method8189(var2);
         return true;
      }
   }

   @ObfuscatedName("bo")
   @ObfuscatedSignature(
      descriptor = "(Lrf;I)V",
      garbageValue = "-1690044546"
   )
   final void method8189(User var1) {
      this.remove(var1);
      int var2 = this.method8195(var1);
      if(var2 != -1) {
         this.arrayRemove_base(var2);
         this.method8196(var1);
      }
   }

   @ObfuscatedName("bt")
   @ObfuscatedSignature(
      descriptor = "(Lvj;B)Lrf;",
      garbageValue = "-83"
   )
   User method8190(Username var1) {
      return this.method8191(var1, (Username)null);
   }

   @ObfuscatedName("bu")
   @ObfuscatedSignature(
      descriptor = "(Lvj;Lvj;I)Lrf;",
      garbageValue = "1851941311"
   )
   User method8191(Username var1, Username var2) {
      if(this.method8222(var1) != null) {
         throw new IllegalStateException();
      } else {
         User var3 = this.vmethod8212();
         var3.method8152(var1, var2);
         this.method8197(var3);
         this.method8210(var3);
         this.add(var1, var2);
         return var3;
      }
   }

   @ObfuscatedName("by")
   @ObfuscatedSignature(
      descriptor = "(II)Lrf;",
      garbageValue = "241913157"
   )
   public final User method8192(int var1) {
      if(var1 >= 0 && var1 < this.size) {
         return this.array[var1];
      } else {
         throw new ArrayIndexOutOfBoundsException(var1);
      }
   }

   @ObfuscatedName("bh")
   @ObfuscatedSignature(
      descriptor = "(B)V",
      garbageValue = "117"
   )
   public final void sort_base() {
      if(this.comparator == null) {
         Arrays.sort(this.array, 0, this.size);
      } else {
         Arrays.sort(this.array, 0, this.size, this.comparator);
      }

   }

   @ObfuscatedName("bz")
   @ObfuscatedSignature(
      descriptor = "(Lrf;Lvj;Lvj;B)V",
      garbageValue = "30"
   )
   final void method8194(User var1, Username var2, Username var3) {
      this.method8196(var1);
      var1.method8152(var2, var3);
      this.method8210(var1);
   }

   @ObfuscatedName("bc")
   @ObfuscatedSignature(
      descriptor = "(Lrf;B)I",
      garbageValue = "-102"
   )
   final int method8195(User var1) {
      for(int var2 = 0; var2 < this.size; ++var2) {
         if(this.array[var2] == var1) {
            return var2;
         }
      }

      return -1;
   }

   @ObfuscatedName("bs")
   @ObfuscatedSignature(
      descriptor = "(Lrf;B)V",
      garbageValue = "-78"
   )
   final void method8196(User var1) {
      if(var1.previousUsername != null) {
         this.previousUsernamesMap.remove(var1.previousUsername);
      }

   }

   @ObfuscatedName("bx")
   @ObfuscatedSignature(
      descriptor = "(Lrf;I)V",
      garbageValue = "-488058670"
   )
   final void method8197(User var1) {
      this.array[++this.size - 1] = var1;
   }

   @ObfuscatedName("bb")
   @ObfuscatedSignature(
      descriptor = "(Lrf;I)V",
      garbageValue = "-1090734641"
   )
   final void method8210(User var1) {
      this.usernamesMap.put(var1.username, var1);
      if(var1.previousUsername != null) {
         User var2 = (User)this.previousUsernamesMap.put(var1.previousUsername, var1);
         if(var2 != null && var2 != var1) {
            var2.previousUsername = null;
            var2.onPrevNameChanged(-1);
         }
      }

   }

   @ObfuscatedName("bk")
   @ObfuscatedSignature(
      descriptor = "(II)V",
      garbageValue = "-312876519"
   )
   final void arrayRemove_base(int var1) {
      --this.size;
      if(var1 < this.size) {
         System.arraycopy(this.array, var1 + 1, this.array, var1, this.size - var1);
      }

   }

   @ObfuscatedName("br")
   @ObfuscatedSignature(
      descriptor = "(I)V",
      garbageValue = "1908013155"
   )
   public final void removeComparator_base() {
      this.comparator = null;
   }

   @ObfuscatedName("bq")
   @ObfuscatedSignature(
      descriptor = "(Ljava/util/Comparator;S)V",
      garbageValue = "-18324"
   )
   public final void addComparator_base(Comparator var1) {
      if(this.comparator == null) {
         this.comparator = var1;
      } else if(this.comparator instanceof AbstractUserComparator) {
         ((AbstractUserComparator)this.comparator).addComparator_base(var1);
      }

   }

   public Nameable[] getNameables() {
      return this.array;
   }

   public void rl$add(RSUsername var1, RSUsername var2) {
   }

   public void rl$remove(RSUser var1) {
   }

   public void remove(RSUser var1) {
      this.rl$remove(var1);
   }

   public T findByName(RSUsername var1) {
      return (T) this.method8185((Username)var1);
   }

   public int getCount() {
      return this.getSize_base();
   }

   public void add(RSUsername var1, RSUsername var2) {
      this.rl$add(var1, var2);
   }

   public T[] getMembers() {
      Nameable[] var1 = this.getNameables();
      int var2 = this.getCount();
      return (T[])Arrays.copyOf(var1, var2);
   }

   public T findByName(String var1) {
      return this.findByName(SpriteMask.client.createName(var1, SpriteMask.client.getLoginType()));
   }

   public int getSize() {
      return this.capacity;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(IS)Lhy;",
      garbageValue = "196"
   )
   public static StructComposition method8260(int var0) {
      StructComposition var1 = Client.copy$StructDefinition_getStructDefinition(var0, (short)196);
      if(var1.getId() == -1) {
         var1.setId(var0);
         PostStructComposition var2 = new PostStructComposition();
         var2.setStructComposition(var1);
         SpriteMask.client.getCallbacks().post(var2);
      }

      return (StructComposition)var1;
   }
}
