// 
// 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 ParticleAnimationFrame
{
    public static final int NULLABLE_BIT_FIELD_SIZE = 1;
    public static final int FIXED_BLOCK_SIZE = 58;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 58;
    public static final int MAX_SIZE = 58;
    @Nullable
    public Range frameIndex;
    @Nullable
    public RangeVector2f scale;
    @Nullable
    public RangeVector3f rotation;
    @Nullable
    public Color color;
    public float opacity;
    
    public ParticleAnimationFrame() {
    }
    
    public ParticleAnimationFrame(@Nullable final Range frameIndex, @Nullable final RangeVector2f scale, @Nullable final RangeVector3f rotation, @Nullable final Color color, final float opacity) {
        this.frameIndex = frameIndex;
        this.scale = scale;
        this.rotation = rotation;
        this.color = color;
        this.opacity = opacity;
    }
    
    public ParticleAnimationFrame(@Nonnull final ParticleAnimationFrame other) {
        this.frameIndex = other.frameIndex;
        this.scale = other.scale;
        this.rotation = other.rotation;
        this.color = other.color;
        this.opacity = other.opacity;
    }
    
    @Nonnull
    public static ParticleAnimationFrame deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final ParticleAnimationFrame obj = new ParticleAnimationFrame();
        final byte nullBits = buf.getByte(offset);
        if ((nullBits & 0x1) != 0x0) {
            obj.frameIndex = Range.deserialize(buf, offset + 1);
        }
        if ((nullBits & 0x2) != 0x0) {
            obj.scale = RangeVector2f.deserialize(buf, offset + 9);
        }
        if ((nullBits & 0x4) != 0x0) {
            obj.rotation = RangeVector3f.deserialize(buf, offset + 26);
        }
        if ((nullBits & 0x8) != 0x0) {
            obj.color = Color.deserialize(buf, offset + 51);
        }
        obj.opacity = buf.getFloatLE(offset + 54);
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 58;
    }
    
    public void serialize(@Nonnull final ByteBuf buf) {
        byte nullBits = 0;
        if (this.frameIndex != null) {
            nullBits |= 0x1;
        }
        if (this.scale != null) {
            nullBits |= 0x2;
        }
        if (this.rotation != null) {
            nullBits |= 0x4;
        }
        if (this.color != null) {
            nullBits |= 0x8;
        }
        buf.writeByte(nullBits);
        if (this.frameIndex != null) {
            this.frameIndex.serialize(buf);
        }
        else {
            buf.writeZero(8);
        }
        if (this.scale != null) {
            this.scale.serialize(buf);
        }
        else {
            buf.writeZero(17);
        }
        if (this.rotation != null) {
            this.rotation.serialize(buf);
        }
        else {
            buf.writeZero(25);
        }
        if (this.color != null) {
            this.color.serialize(buf);
        }
        else {
            buf.writeZero(3);
        }
        buf.writeFloatLE(this.opacity);
    }
    
    public int computeSize() {
        return 58;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 58) {
            return ValidationResult.error("Buffer too small: expected at least 58 bytes");
        }
        return ValidationResult.OK;
    }
    
    public ParticleAnimationFrame clone() {
        final ParticleAnimationFrame copy = new ParticleAnimationFrame();
        copy.frameIndex = ((this.frameIndex != null) ? this.frameIndex.clone() : null);
        copy.scale = ((this.scale != null) ? this.scale.clone() : null);
        copy.rotation = ((this.rotation != null) ? this.rotation.clone() : null);
        copy.color = ((this.color != null) ? this.color.clone() : null);
        copy.opacity = this.opacity;
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final ParticleAnimationFrame other) {
            return Objects.equals(this.frameIndex, other.frameIndex) && Objects.equals(this.scale, other.scale) && Objects.equals(this.rotation, other.rotation) && Objects.equals(this.color, other.color) && this.opacity == other.opacity;
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.frameIndex, this.scale, this.rotation, this.color, this.opacity);
    }
}
