// 
// 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;

public class SlotTransaction implements Transaction
{
    public static final SlotTransaction FAILED_ADD;
    private final boolean succeeded;
    @Nonnull
    private final ActionType action;
    private final short slot;
    @Nullable
    private final ItemStack slotBefore;
    @Nullable
    private final ItemStack slotAfter;
    @Nullable
    private final ItemStack output;
    private final boolean allOrNothing;
    private final boolean exactAmount;
    private final boolean filter;
    
    public SlotTransaction(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) {
        this.succeeded = succeeded;
        this.action = action;
        this.slot = slot;
        this.slotBefore = slotBefore;
        this.slotAfter = slotAfter;
        this.output = output;
        this.allOrNothing = allOrNothing;
        this.exactAmount = exactAmount;
        this.filter = filter;
    }
    
    @Override
    public boolean succeeded() {
        return this.succeeded;
    }
    
    @Override
    public boolean wasSlotModified(final short slot) {
        return this.succeeded && this.slot == slot;
    }
    
    @Nonnull
    public ActionType getAction() {
        return this.action;
    }
    
    public short getSlot() {
        return this.slot;
    }
    
    @Nullable
    public ItemStack getSlotBefore() {
        return this.slotBefore;
    }
    
    @Nullable
    public ItemStack getSlotAfter() {
        return this.slotAfter;
    }
    
    @Nullable
    public ItemStack getOutput() {
        return this.output;
    }
    
    public boolean isAllOrNothing() {
        return this.allOrNothing;
    }
    
    public boolean isExactAmount() {
        return this.exactAmount;
    }
    
    public boolean isFilter() {
        return this.filter;
    }
    
    @Nonnull
    @Override
    public SlotTransaction toParent(final ItemContainer parent, final short start, final ItemContainer container) {
        final short newSlot = (short)(start + this.slot);
        return new SlotTransaction(this.succeeded, this.action, newSlot, this.slotBefore, this.slotAfter, this.output, this.allOrNothing, this.exactAmount, this.filter);
    }
    
    @Nullable
    @Override
    public SlotTransaction fromParent(final ItemContainer parent, final short start, @Nonnull final ItemContainer container) {
        final short newSlot = (short)(this.slot - start);
        if (newSlot < 0 || newSlot >= container.getCapacity()) {
            return null;
        }
        return new SlotTransaction(this.succeeded, this.action, newSlot, this.slotBefore, this.slotAfter, this.output, this.allOrNothing, this.exactAmount, this.filter);
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "SlotTransaction{succeeded=" + this.succeeded + ", action=" + String.valueOf(this.action) + ", slot=" + this.slot + ", slotBefore=" + String.valueOf(this.slotBefore) + ", slotAfter=" + String.valueOf(this.slotAfter) + ", allOrNothing=" + this.allOrNothing + ", exactAmount=" + this.exactAmount + ", filter=" + this.filter;
    }
    
    static {
        FAILED_ADD = new SlotTransaction(false, ActionType.ADD, (short)(-1), null, null, null, false, false, false);
    }
}
