package mapped;

import java.util.Iterator;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSDualNode;
import net.runelite.rs.api.RSIterableDualNodeQueue;

@ObfuscatedName("po")
public class IterableDualNodeQueue implements Iterable, RSIterableDualNodeQueue {
   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "Lsn;"
   )
   public DualNode sentinel;
   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "Lsn;"
   )
   DualNode head;

   public IterableDualNodeQueue() {
      this.sentinel = new DualNode();
      this.sentinel.previousDual = this.sentinel;
      this.sentinel.nextDual = this.sentinel;
   }

   @ObfuscatedName("at")
   public void clear_base() {
      while(this.sentinel.previousDual != this.sentinel) {
         this.sentinel.previousDual.removeDual_base();
      }

   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Lsn;)V"
   )
   public void method7382(DualNode var1) {
      if(var1.nextDual != null) {
         var1.removeDual_base();
      }

      var1.nextDual = this.sentinel.nextDual;
      var1.previousDual = this.sentinel;
      var1.nextDual.previousDual = var1;
      var1.previousDual.nextDual = var1;
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "()Lsn;"
   )
   public DualNode method7384() {
      DualNode var1 = this.sentinel.previousDual;
      if(var1 == this.sentinel) {
         return null;
      } else {
         var1.removeDual_base();
         return var1;
      }
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "()Lsn;"
   )
   public DualNode method7385() {
      return this.method7393((DualNode)null);
   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "(Lsn;)Lsn;"
   )
   DualNode method7393(DualNode var1) {
      DualNode var2;
      if(var1 == null) {
         var2 = this.sentinel.previousDual;
      } else {
         var2 = var1;
      }

      if(var2 == this.sentinel) {
         this.head = null;
         return null;
      } else {
         this.head = var2.previousDual;
         return var2;
      }
   }

   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "()Lsn;"
   )
   public DualNode method7387() {
      DualNode var1 = this.head;
      if(var1 == this.sentinel) {
         this.head = null;
         return null;
      } else {
         this.head = var1.previousDual;
         return var1;
      }
   }

   public Iterator iterator() {
      return new IterableDualNodeQueueIterator(this);
   }

   public void add(RSDualNode var1) {
      this.method7382((DualNode)var1);
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(Lsn;Lsn;)V"
   )
   public static void method7383(DualNode var0, DualNode var1) {
      if(var0.nextDual != null) {
         var0.removeDual_base();
      }

      var0.nextDual = var1;
      var0.previousDual = var1.previousDual;
      var0.nextDual.previousDual = var0;
      var0.previousDual.nextDual = var0;
   }
}
