// 
// 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 BlockRotation
{
    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 Rotation rotationYaw;
    @Nonnull
    public Rotation rotationPitch;
    @Nonnull
    public Rotation rotationRoll;
    
    public BlockRotation() {
        this.rotationYaw = Rotation.None;
        this.rotationPitch = Rotation.None;
        this.rotationRoll = Rotation.None;
    }
    
    public BlockRotation(@Nonnull final Rotation rotationYaw, @Nonnull final Rotation rotationPitch, @Nonnull final Rotation rotationRoll) {
        this.rotationYaw = Rotation.None;
        this.rotationPitch = Rotation.None;
        this.rotationRoll = Rotation.None;
        this.rotationYaw = rotationYaw;
        this.rotationPitch = rotationPitch;
        this.rotationRoll = rotationRoll;
    }
    
    public BlockRotation(@Nonnull final BlockRotation other) {
        this.rotationYaw = Rotation.None;
        this.rotationPitch = Rotation.None;
        this.rotationRoll = Rotation.None;
        this.rotationYaw = other.rotationYaw;
        this.rotationPitch = other.rotationPitch;
        this.rotationRoll = other.rotationRoll;
    }
    
    @Nonnull
    public static BlockRotation deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final BlockRotation obj = new BlockRotation();
        obj.rotationYaw = Rotation.fromValue(buf.getByte(offset + 0));
        obj.rotationPitch = Rotation.fromValue(buf.getByte(offset + 1));
        obj.rotationRoll = Rotation.fromValue(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.rotationYaw.getValue());
        buf.writeByte(this.rotationPitch.getValue());
        buf.writeByte(this.rotationRoll.getValue());
    }
    
    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 BlockRotation clone() {
        final BlockRotation copy = new BlockRotation();
        copy.rotationYaw = this.rotationYaw;
        copy.rotationPitch = this.rotationPitch;
        copy.rotationRoll = this.rotationRoll;
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final BlockRotation other) {
            return Objects.equals(this.rotationYaw, other.rotationYaw) && Objects.equals(this.rotationPitch, other.rotationPitch) && Objects.equals(this.rotationRoll, other.rotationRoll);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.rotationYaw, this.rotationPitch, this.rotationRoll);
    }
}
