package mapped;

import net.runelite.api.GrandExchangeOfferState;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSGrandExchangeOffer;

@ObfuscatedName("ow")
public class GrandExchangeOffer implements RSGrandExchangeOffer {
   @ObfuscatedName("at")
   byte state;
   @ObfuscatedName("ah")
   @ObfuscatedGetter(
      intValue = -1703369019
   )
   public int id;
   @ObfuscatedName("ar")
   @ObfuscatedGetter(
      intValue = 1283863875
   )
   public int unitPrice;
   @ObfuscatedName("ao")
   @ObfuscatedGetter(
      intValue = -1833506105
   )
   public int totalQuantity;
   @ObfuscatedName("ab")
   @ObfuscatedGetter(
      intValue = 856281189
   )
   public int currentQuantity;
   @ObfuscatedName("au")
   @ObfuscatedGetter(
      intValue = 1135311229
   )
   public int currentPrice;

   public GrandExchangeOffer() {
   }

   @ObfuscatedSignature(
      descriptor = "(Luj;Z)V",
      garbageValue = "0"
   )
   public GrandExchangeOffer(Buffer var1, boolean var2) {
      this.state = var1.readByte_base();
      this.id = var1.readUnsignedShort_base();
      this.unitPrice = var1.readInt_base();
      this.totalQuantity = var1.readInt_base();
      this.currentQuantity = var1.readInt_base();
      this.currentPrice = var1.readInt_base();
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "-1302720391"
   )
   public int status_base() {
      return this.state & 7;
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(I)I",
      garbageValue = "-1911768409"
   )
   public int type_base() {
      return (this.state & 8) == 8?1:0;
   }

   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "(II)V",
      garbageValue = "-2128384441"
   )
   void method7143_base(int var1) {
      this.state &= -8;
      this.state = (byte)(this.state | var1 & 7);
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(II)V",
      garbageValue = "830444255"
   )
   void method7133_base(int var1) {
      this.state &= -9;
      if(var1 == 1) {
         this.state = (byte)(this.state | 8);
      }

   }

   public byte getRSState() {
      return this.state;
   }

   public int getQuantitySold() {
      return this.currentQuantity;
   }

   public int getTotalQuantity() {
      return this.totalQuantity;
   }

   public GrandExchangeOfferState getState() {
      byte var1 = this.getRSState();
      boolean var2 = (var1 & 8) == 8;
      boolean var3 = (var1 & 4) == 4;
      return var1 == 0?GrandExchangeOfferState.EMPTY:(var3 && this.getQuantitySold() < this.getTotalQuantity()?(var2?GrandExchangeOfferState.CANCELLED_SELL:GrandExchangeOfferState.CANCELLED_BUY):(var2?(var3?GrandExchangeOfferState.SOLD:GrandExchangeOfferState.SELLING):(var3?GrandExchangeOfferState.BOUGHT:GrandExchangeOfferState.BUYING)));
   }

   public int getItemId() {
      return this.id;
   }

   public int getPrice() {
      return this.unitPrice;
   }

   public int getSpent() {
      return this.currentPrice;
   }
}
