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