package mapped;

import net.runelite.api.MessageNode;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSChatChannel;
import net.runelite.rs.api.RSDualNode;
import net.runelite.rs.api.RSMessage;

@ObfuscatedName("dk")
public class ChatChannel implements RSChatChannel {
   @ObfuscatedName("al")
   static int[] field996;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "[Lco;"
   )
   Message[] messages;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = 2075244397
   )
   int count;

   ChatChannel() {
      this.messages = new Message[100];
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Lco;",
      garbageValue = "-698368105"
   )
   Message method2247(int var1, String var2, String var3, String var4) {
      Message var5 = this.messages[99];

      for(int var6 = this.count; var6 > 0; --var6) {
         if(var6 != 100) {
            this.messages[var6] = this.messages[var6 - 1];
         }
      }

      if(var5 == null) {
         var5 = new Message(var1, var2, var4, var3);
      } else {
         var5.remove_base();
         var5.removeDual_base();
         var5.set_base(var1, var2, var4, var3);
      }

      this.messages[0] = var5;
      if(this.count < 100) {
         ++this.count;
      }

      return var5;
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(II)Lco;",
      garbageValue = "-649876518"
   )
   Message method2248(int var1) {
      return var1 >= 0 && var1 < this.count?this.messages[var1]:null;
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "519230888"
   )
   int size_base() {
      return this.count;
   }

   public RSMessage[] getLines() {
      return this.messages;
   }

   public int getLength() {
      return this.count;
   }

   public void setLength(int var1) {
      this.count = var1;
   }

   public void removeMessageNode(MessageNode var1) {
      RSMessage[] var2 = this.getLines();
      int var3 = this.getLength();
      int var4 = -1;

      int var5;
      for(var5 = 0; var5 < var3; ++var5) {
         if(var2[var5] == var1) {
            var4 = var5;
            break;
         }
      }

      if(var4 != -1) {
         for(var5 = var4; var5 < var3 - 1; ++var5) {
            var2[var5] = var2[var5 + 1];
         }

         var2[var3 - 1] = null;
         this.setLength(var3 - 1);
         RSDualNode var6 = (RSDualNode)var1;
         var6.unlink();
         var6.unlinkDual();
      }
   }
}
