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