// 
// 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 Modifier
{
    public static final int NULLABLE_BIT_FIELD_SIZE = 0;
    public static final int FIXED_BLOCK_SIZE = 6;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 6;
    public static final int MAX_SIZE = 6;
    @Nonnull
    public ModifierTarget target;
    @Nonnull
    public CalculationType calculationType;
    public float amount;
    
    public Modifier() {
        this.target = ModifierTarget.Min;
        this.calculationType = CalculationType.Additive;
    }
    
    public Modifier(@Nonnull final ModifierTarget target, @Nonnull final CalculationType calculationType, final float amount) {
        this.target = ModifierTarget.Min;
        this.calculationType = CalculationType.Additive;
        this.target = target;
        this.calculationType = calculationType;
        this.amount = amount;
    }
    
    public Modifier(@Nonnull final Modifier other) {
        this.target = ModifierTarget.Min;
        this.calculationType = CalculationType.Additive;
        this.target = other.target;
        this.calculationType = other.calculationType;
        this.amount = other.amount;
    }
    
    @Nonnull
    public static Modifier deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final Modifier obj = new Modifier();
        obj.target = ModifierTarget.fromValue(buf.getByte(offset + 0));
        obj.calculationType = CalculationType.fromValue(buf.getByte(offset + 1));
        obj.amount = buf.getFloatLE(offset + 2);
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 6;
    }
    
    public void serialize(@Nonnull final ByteBuf buf) {
        buf.writeByte(this.target.getValue());
        buf.writeByte(this.calculationType.getValue());
        buf.writeFloatLE(this.amount);
    }
    
    public int computeSize() {
        return 6;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 6) {
            return ValidationResult.error("Buffer too small: expected at least 6 bytes");
        }
        return ValidationResult.OK;
    }
    
    public Modifier clone() {
        final Modifier copy = new Modifier();
        copy.target = this.target;
        copy.calculationType = this.calculationType;
        copy.amount = this.amount;
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final Modifier other) {
            return Objects.equals(this.target, other.target) && Objects.equals(this.calculationType, other.calculationType) && this.amount == other.amount;
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.target, this.calculationType, this.amount);
    }
}
