// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.core.inventory.transaction;

import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.core.inventory.ItemStack;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.inventory.ResourceQuantity;

public class ResourceSlotTransaction extends SlotTransaction
{
    @Nonnull
    private final ResourceQuantity query;
    private final int remainder;
    private final int consumed;
    
    public ResourceSlotTransaction(final boolean succeeded, @Nonnull final ActionType action, final short slot, @Nullable final ItemStack slotBefore, @Nullable final ItemStack slotAfter, @Nullable final ItemStack output, final boolean allOrNothing, final boolean exactAmount, final boolean filter, @Nonnull final ResourceQuantity query, final int remainder, final int consumed) {
        super(succeeded, action, slot, slotBefore, slotAfter, output, allOrNothing, exactAmount, filter);
        this.query = query;
        this.remainder = remainder;
        this.consumed = consumed;
    }
    
    @Nonnull
    public ResourceQuantity getQuery() {
        return this.query;
    }
    
    public int getRemainder() {
        return this.remainder;
    }
    
    public int getConsumed() {
        return this.consumed;
    }
    
    @Nonnull
    @Override
    public ResourceSlotTransaction toParent(final ItemContainer parent, final short start, final ItemContainer container) {
        final short newSlot = (short)(start + this.getSlot());
        return new ResourceSlotTransaction(this.succeeded(), this.getAction(), newSlot, this.getSlotBefore(), this.getSlotAfter(), this.getOutput(), this.isAllOrNothing(), this.isExactAmount(), this.isFilter(), this.query, this.remainder, this.consumed);
    }
    
    @Nullable
    @Override
    public ResourceSlotTransaction fromParent(final ItemContainer parent, final short start, @Nonnull final ItemContainer container) {
        final short newSlot = (short)(this.getSlot() - start);
        if (newSlot < 0 || newSlot >= container.getCapacity()) {
            return null;
        }
        return new ResourceSlotTransaction(this.succeeded(), this.getAction(), newSlot, this.getSlotBefore(), this.getSlotAfter(), this.getOutput(), this.isAllOrNothing(), this.isExactAmount(), this.isFilter(), this.query, this.remainder, this.consumed);
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "ResourceSlotTransaction{query=" + String.valueOf(this.query) + ", remainder=" + this.remainder + ", consumed=" + this.consumed + "} " + super.toString();
    }
}
