// 
// 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;
import javax.annotation.Nullable;

public class ItemPullbackConfiguration
{
    public static final int NULLABLE_BIT_FIELD_SIZE = 1;
    public static final int FIXED_BLOCK_SIZE = 49;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 49;
    public static final int MAX_SIZE = 49;
    @Nullable
    public Vector3f leftOffsetOverride;
    @Nullable
    public Vector3f leftRotationOverride;
    @Nullable
    public Vector3f rightOffsetOverride;
    @Nullable
    public Vector3f rightRotationOverride;
    
    public ItemPullbackConfiguration() {
    }
    
    public ItemPullbackConfiguration(@Nullable final Vector3f leftOffsetOverride, @Nullable final Vector3f leftRotationOverride, @Nullable final Vector3f rightOffsetOverride, @Nullable final Vector3f rightRotationOverride) {
        this.leftOffsetOverride = leftOffsetOverride;
        this.leftRotationOverride = leftRotationOverride;
        this.rightOffsetOverride = rightOffsetOverride;
        this.rightRotationOverride = rightRotationOverride;
    }
    
    public ItemPullbackConfiguration(@Nonnull final ItemPullbackConfiguration other) {
        this.leftOffsetOverride = other.leftOffsetOverride;
        this.leftRotationOverride = other.leftRotationOverride;
        this.rightOffsetOverride = other.rightOffsetOverride;
        this.rightRotationOverride = other.rightRotationOverride;
    }
    
    @Nonnull
    public static ItemPullbackConfiguration deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final ItemPullbackConfiguration obj = new ItemPullbackConfiguration();
        final byte nullBits = buf.getByte(offset);
        if ((nullBits & 0x1) != 0x0) {
            obj.leftOffsetOverride = Vector3f.deserialize(buf, offset + 1);
        }
        if ((nullBits & 0x2) != 0x0) {
            obj.leftRotationOverride = Vector3f.deserialize(buf, offset + 13);
        }
        if ((nullBits & 0x4) != 0x0) {
            obj.rightOffsetOverride = Vector3f.deserialize(buf, offset + 25);
        }
        if ((nullBits & 0x8) != 0x0) {
            obj.rightRotationOverride = Vector3f.deserialize(buf, offset + 37);
        }
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 49;
    }
    
    public void serialize(@Nonnull final ByteBuf buf) {
        byte nullBits = 0;
        if (this.leftOffsetOverride != null) {
            nullBits |= 0x1;
        }
        if (this.leftRotationOverride != null) {
            nullBits |= 0x2;
        }
        if (this.rightOffsetOverride != null) {
            nullBits |= 0x4;
        }
        if (this.rightRotationOverride != null) {
            nullBits |= 0x8;
        }
        buf.writeByte(nullBits);
        if (this.leftOffsetOverride != null) {
            this.leftOffsetOverride.serialize(buf);
        }
        else {
            buf.writeZero(12);
        }
        if (this.leftRotationOverride != null) {
            this.leftRotationOverride.serialize(buf);
        }
        else {
            buf.writeZero(12);
        }
        if (this.rightOffsetOverride != null) {
            this.rightOffsetOverride.serialize(buf);
        }
        else {
            buf.writeZero(12);
        }
        if (this.rightRotationOverride != null) {
            this.rightRotationOverride.serialize(buf);
        }
        else {
            buf.writeZero(12);
        }
    }
    
    public int computeSize() {
        return 49;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 49) {
            return ValidationResult.error("Buffer too small: expected at least 49 bytes");
        }
        return ValidationResult.OK;
    }
    
    public ItemPullbackConfiguration clone() {
        final ItemPullbackConfiguration copy = new ItemPullbackConfiguration();
        copy.leftOffsetOverride = ((this.leftOffsetOverride != null) ? this.leftOffsetOverride.clone() : null);
        copy.leftRotationOverride = ((this.leftRotationOverride != null) ? this.leftRotationOverride.clone() : null);
        copy.rightOffsetOverride = ((this.rightOffsetOverride != null) ? this.rightOffsetOverride.clone() : null);
        copy.rightRotationOverride = ((this.rightRotationOverride != null) ? this.rightRotationOverride.clone() : null);
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final ItemPullbackConfiguration other) {
            return Objects.equals(this.leftOffsetOverride, other.leftOffsetOverride) && Objects.equals(this.leftRotationOverride, other.leftRotationOverride) && Objects.equals(this.rightOffsetOverride, other.rightOffsetOverride) && Objects.equals(this.rightRotationOverride, other.rightRotationOverride);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.leftOffsetOverride, this.leftRotationOverride, this.rightOffsetOverride, this.rightRotationOverride);
    }
}
