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