// 
// 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 VelocityConfig
{
    public static final int NULLABLE_BIT_FIELD_SIZE = 0;
    public static final int FIXED_BLOCK_SIZE = 21;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 21;
    public static final int MAX_SIZE = 21;
    public float groundResistance;
    public float groundResistanceMax;
    public float airResistance;
    public float airResistanceMax;
    public float threshold;
    @Nonnull
    public VelocityThresholdStyle style;
    
    public VelocityConfig() {
        this.style = VelocityThresholdStyle.Linear;
    }
    
    public VelocityConfig(final float groundResistance, final float groundResistanceMax, final float airResistance, final float airResistanceMax, final float threshold, @Nonnull final VelocityThresholdStyle style) {
        this.style = VelocityThresholdStyle.Linear;
        this.groundResistance = groundResistance;
        this.groundResistanceMax = groundResistanceMax;
        this.airResistance = airResistance;
        this.airResistanceMax = airResistanceMax;
        this.threshold = threshold;
        this.style = style;
    }
    
    public VelocityConfig(@Nonnull final VelocityConfig other) {
        this.style = VelocityThresholdStyle.Linear;
        this.groundResistance = other.groundResistance;
        this.groundResistanceMax = other.groundResistanceMax;
        this.airResistance = other.airResistance;
        this.airResistanceMax = other.airResistanceMax;
        this.threshold = other.threshold;
        this.style = other.style;
    }
    
    @Nonnull
    public static VelocityConfig deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final VelocityConfig obj = new VelocityConfig();
        obj.groundResistance = buf.getFloatLE(offset + 0);
        obj.groundResistanceMax = buf.getFloatLE(offset + 4);
        obj.airResistance = buf.getFloatLE(offset + 8);
        obj.airResistanceMax = buf.getFloatLE(offset + 12);
        obj.threshold = buf.getFloatLE(offset + 16);
        obj.style = VelocityThresholdStyle.fromValue(buf.getByte(offset + 20));
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 21;
    }
    
    public void serialize(@Nonnull final ByteBuf buf) {
        buf.writeFloatLE(this.groundResistance);
        buf.writeFloatLE(this.groundResistanceMax);
        buf.writeFloatLE(this.airResistance);
        buf.writeFloatLE(this.airResistanceMax);
        buf.writeFloatLE(this.threshold);
        buf.writeByte(this.style.getValue());
    }
    
    public int computeSize() {
        return 21;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 21) {
            return ValidationResult.error("Buffer too small: expected at least 21 bytes");
        }
        return ValidationResult.OK;
    }
    
    public VelocityConfig clone() {
        final VelocityConfig copy = new VelocityConfig();
        copy.groundResistance = this.groundResistance;
        copy.groundResistanceMax = this.groundResistanceMax;
        copy.airResistance = this.airResistance;
        copy.airResistanceMax = this.airResistanceMax;
        copy.threshold = this.threshold;
        copy.style = this.style;
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final VelocityConfig other) {
            return this.groundResistance == other.groundResistance && this.groundResistanceMax == other.groundResistanceMax && this.airResistance == other.airResistance && this.airResistanceMax == other.airResistanceMax && this.threshold == other.threshold && Objects.equals(this.style, other.style);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.groundResistance, this.groundResistanceMax, this.airResistance, this.airResistanceMax, this.threshold, this.style);
    }
}
