// 
// 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.InventoryActionType;
import com.hypixel.hytale.protocol.Packet;

public class InventoryAction implements Packet
{
    public static final int PACKET_ID = 179;
    public static final boolean IS_COMPRESSED = false;
    public static final int NULLABLE_BIT_FIELD_SIZE = 0;
    public static final int FIXED_BLOCK_SIZE = 6;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 6;
    public static final int MAX_SIZE = 6;
    public int inventorySectionId;
    @Nonnull
    public InventoryActionType inventoryActionType;
    public byte actionData;
    
    @Override
    public int getId() {
        return 179;
    }
    
    public InventoryAction() {
        this.inventoryActionType = InventoryActionType.TakeAll;
    }
    
    public InventoryAction(final int inventorySectionId, @Nonnull final InventoryActionType inventoryActionType, final byte actionData) {
        this.inventoryActionType = InventoryActionType.TakeAll;
        this.inventorySectionId = inventorySectionId;
        this.inventoryActionType = inventoryActionType;
        this.actionData = actionData;
    }
    
    public InventoryAction(@Nonnull final InventoryAction other) {
        this.inventoryActionType = InventoryActionType.TakeAll;
        this.inventorySectionId = other.inventorySectionId;
        this.inventoryActionType = other.inventoryActionType;
        this.actionData = other.actionData;
    }
    
    @Nonnull
    public static InventoryAction deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final InventoryAction obj = new InventoryAction();
        obj.inventorySectionId = buf.getIntLE(offset + 0);
        obj.inventoryActionType = InventoryActionType.fromValue(buf.getByte(offset + 4));
        obj.actionData = buf.getByte(offset + 5);
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 6;
    }
    
    @Override
    public void serialize(@Nonnull final ByteBuf buf) {
        buf.writeIntLE(this.inventorySectionId);
        buf.writeByte(this.inventoryActionType.getValue());
        buf.writeByte(this.actionData);
    }
    
    @Override
    public int computeSize() {
        return 6;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 6) {
            return ValidationResult.error("Buffer too small: expected at least 6 bytes");
        }
        return ValidationResult.OK;
    }
    
    public InventoryAction clone() {
        final InventoryAction copy = new InventoryAction();
        copy.inventorySectionId = this.inventorySectionId;
        copy.inventoryActionType = this.inventoryActionType;
        copy.actionData = this.actionData;
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final InventoryAction other) {
            return this.inventorySectionId == other.inventorySectionId && Objects.equals(this.inventoryActionType, other.inventoryActionType) && this.actionData == other.actionData;
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.inventorySectionId, this.inventoryActionType, this.actionData);
    }
}
