package mapped;

import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSUsername;

@ObfuscatedName("vj")
public class Username implements Comparable, RSUsername {
   @ObfuscatedName("at")
   String name;
   @ObfuscatedName("ah")
   String cleanName;

   @ObfuscatedSignature(
      descriptor = "(Ljava/lang/String;Ltt;)V"
   )
   public Username(String var1, LoginType var2) {
      this.name = var1;
      this.cleanName = class14.method180(var1, var2);
   }

   public Username(String var1) {
      this.name = var1;
      LoginType var4 = LoginType.oldscape;
      String var3;
      if(var1 == null) {
         var3 = null;
      } else {
         label100: {
            int var5 = 0;

            int var6;
            for(var6 = var1.length(); var5 < var6 && class489.method8666_base(var1.charAt(var5)); ++var5) {
               ;
            }

            while(var6 > var5 && class489.method8666_base(var1.charAt(var6 - 1))) {
               --var6;
            }

            int var7 = var6 - var5;
            if(var7 >= 1) {
               byte var9;
               if(var4 == null) {
                  var9 = 12;
               } else {
                  switch(var4.field5022) {
                  case 1:
                     var9 = 20;
                     break;
                  default:
                     var9 = 12;
                  }
               }

               if(var7 <= var9) {
                  StringBuilder var15 = new StringBuilder(var7);

                  for(int var17 = var5; var17 < var6; ++var17) {
                     char var10 = var1.charAt(var17);
                     boolean var11;
                     if(Character.isISOControl(var10)) {
                        var11 = false;
                     } else if(KeyHandler.isAlphaNumeric_base(var10)) {
                        var11 = true;
                     } else {
                        char[] var16 = class505.field5030;
                        int var13 = 0;

                        label67:
                        while(true) {
                           char var14;
                           if(var13 >= var16.length) {
                              var16 = class505.field5031;

                              for(var13 = 0; var13 < var16.length; ++var13) {
                                 var14 = var16[var13];
                                 if(var14 == var10) {
                                    var11 = true;
                                    break label67;
                                 }
                              }

                              var11 = false;
                              break;
                           }

                           var14 = var16[var13];
                           if(var10 == var14) {
                              var11 = true;
                              break;
                           }

                           ++var13;
                        }
                     }

                     if(var11) {
                        char var12 = FriendsChat.method8113_base(var10);
                        if(var12 != 0) {
                           var15.append(var12);
                        }
                     }
                  }

                  if(var15.length() == 0) {
                     var3 = null;
                  } else {
                     var3 = var15.toString();
                  }
                  break label100;
               }
            }

            var3 = null;
         }
      }

      this.cleanName = var3;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(B)Ljava/lang/String;",
      garbageValue = "8"
   )
   public String getName_base() {
      return this.name;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(I)Ljava/lang/String;",
      garbageValue = "-1344600615"
   )
   public String method9937_base() {
      return this.cleanName;
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(B)Z",
      garbageValue = "-91"
   )
   public boolean hasCleanName_base() {
      return this.cleanName != null;
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(Lvj;I)I",
      garbageValue = "1848187995"
   )
   public int method9958(Username var1) {
      return this.cleanName == null?(var1.cleanName == null?0:1):(var1.cleanName == null?-1:this.cleanName.compareTo(var1.cleanName));
   }

   public boolean equals(Object var1) {
      if(var1 instanceof Username) {
         Username var2 = (Username)var1;
         return this.cleanName == null?var2.cleanName == null:(var2.cleanName == null?false:(this.hashCode() != var2.hashCode()?false:this.cleanName.equals(var2.cleanName)));
      } else {
         return false;
      }
   }

   public int hashCode() {
      return this.cleanName == null?0:this.cleanName.hashCode();
   }

   public String toString() {
      return this.getName_base();
   }

   public int compareTo(Object var1) {
      return this.method9958((Username)var1);
   }

   public String getName() {
      return this.getName_base();
   }
}
