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

package com.hypixel.hytale.protocol.packets.inventory;

import java.util.Objects;
import com.hypixel.hytale.protocol.io.ValidationResult;
import io.netty.buffer.ByteBuf;
import javax.annotation.Nonnull;
import com.hypixel.hytale.protocol.SmartMoveType;
import com.hypixel.hytale.protocol.Packet;

public class SmartMoveItemStack implements Packet
{
    public static final int PACKET_ID = 176;
    public static final boolean IS_COMPRESSED = false;
    public static final int NULLABLE_BIT_FIELD_SIZE = 0;
    public static final int FIXED_BLOCK_SIZE = 13;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 13;
    public static final int MAX_SIZE = 13;
    public int fromSectionId;
    public int fromSlotId;
    public int quantity;
    @Nonnull
    public SmartMoveType moveType;
    
    @Override
    public int getId() {
        return 176;
    }
    
    public SmartMoveItemStack() {
        this.moveType = SmartMoveType.EquipOrMergeStack;
    }
    
    public SmartMoveItemStack(final int fromSectionId, final int fromSlotId, final int quantity, @Nonnull final SmartMoveType moveType) {
        this.moveType = SmartMoveType.EquipOrMergeStack;
        this.fromSectionId = fromSectionId;
        this.fromSlotId = fromSlotId;
        this.quantity = quantity;
        this.moveType = moveType;
    }
    
    public SmartMoveItemStack(@Nonnull final SmartMoveItemStack other) {
        this.moveType = SmartMoveType.EquipOrMergeStack;
        this.fromSectionId = other.fromSectionId;
        this.fromSlotId = other.fromSlotId;
        this.quantity = other.quantity;
        this.moveType = other.moveType;
    }
    
    @Nonnull
    public static SmartMoveItemStack deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final SmartMoveItemStack obj = new SmartMoveItemStack();
        obj.fromSectionId = buf.getIntLE(offset + 0);
        obj.fromSlotId = buf.getIntLE(offset + 4);
        obj.quantity = buf.getIntLE(offset + 8);
        obj.moveType = SmartMoveType.fromValue(buf.getByte(offset + 12));
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 13;
    }
    
    @Override
    public void serialize(@Nonnull final ByteBuf buf) {
        buf.writeIntLE(this.fromSectionId);
        buf.writeIntLE(this.fromSlotId);
        buf.writeIntLE(this.quantity);
        buf.writeByte(this.moveType.getValue());
    }
    
    @Override
    public int computeSize() {
        return 13;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 13) {
            return ValidationResult.error("Buffer too small: expected at least 13 bytes");
        }
        return ValidationResult.OK;
    }
    
    public SmartMoveItemStack clone() {
        final SmartMoveItemStack copy = new SmartMoveItemStack();
        copy.fromSectionId = this.fromSectionId;
        copy.fromSlotId = this.fromSlotId;
        copy.quantity = this.quantity;
        copy.moveType = this.moveType;
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final SmartMoveItemStack other) {
            return this.fromSectionId == other.fromSectionId && this.fromSlotId == other.fromSlotId && this.quantity == other.quantity && Objects.equals(this.moveType, other.moveType);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.fromSectionId, this.fromSlotId, this.quantity, this.moveType);
    }
}
