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

package com.hypixel.hytale.protocol;

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

public class MouseButtonEvent
{
    public static final int NULLABLE_BIT_FIELD_SIZE = 0;
    public static final int FIXED_BLOCK_SIZE = 3;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 3;
    public static final int MAX_SIZE = 3;
    @Nonnull
    public MouseButtonType mouseButtonType;
    @Nonnull
    public MouseButtonState state;
    public byte clicks;
    
    public MouseButtonEvent() {
        this.mouseButtonType = MouseButtonType.Left;
        this.state = MouseButtonState.Pressed;
    }
    
    public MouseButtonEvent(@Nonnull final MouseButtonType mouseButtonType, @Nonnull final MouseButtonState state, final byte clicks) {
        this.mouseButtonType = MouseButtonType.Left;
        this.state = MouseButtonState.Pressed;
        this.mouseButtonType = mouseButtonType;
        this.state = state;
        this.clicks = clicks;
    }
    
    public MouseButtonEvent(@Nonnull final MouseButtonEvent other) {
        this.mouseButtonType = MouseButtonType.Left;
        this.state = MouseButtonState.Pressed;
        this.mouseButtonType = other.mouseButtonType;
        this.state = other.state;
        this.clicks = other.clicks;
    }
    
    @Nonnull
    public static MouseButtonEvent deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final MouseButtonEvent obj = new MouseButtonEvent();
        obj.mouseButtonType = MouseButtonType.fromValue(buf.getByte(offset + 0));
        obj.state = MouseButtonState.fromValue(buf.getByte(offset + 1));
        obj.clicks = buf.getByte(offset + 2);
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 3;
    }
    
    public void serialize(@Nonnull final ByteBuf buf) {
        buf.writeByte(this.mouseButtonType.getValue());
        buf.writeByte(this.state.getValue());
        buf.writeByte(this.clicks);
    }
    
    public int computeSize() {
        return 3;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 3) {
            return ValidationResult.error("Buffer too small: expected at least 3 bytes");
        }
        return ValidationResult.OK;
    }
    
    public MouseButtonEvent clone() {
        final MouseButtonEvent copy = new MouseButtonEvent();
        copy.mouseButtonType = this.mouseButtonType;
        copy.state = this.state;
        copy.clicks = this.clicks;
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final MouseButtonEvent other) {
            return Objects.equals(this.mouseButtonType, other.mouseButtonType) && Objects.equals(this.state, other.state) && this.clicks == other.clicks;
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.mouseButtonType, this.state, this.clicks);
    }
}
