// 
// 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 AssetIconProperties
{
    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;
    public float scale;
    @Nullable
    public Vector2f translation;
    @Nullable
    public Vector3f rotation;
    
    public AssetIconProperties() {
    }
    
    public AssetIconProperties(final float scale, @Nullable final Vector2f translation, @Nullable final Vector3f rotation) {
        this.scale = scale;
        this.translation = translation;
        this.rotation = rotation;
    }
    
    public AssetIconProperties(@Nonnull final AssetIconProperties other) {
        this.scale = other.scale;
        this.translation = other.translation;
        this.rotation = other.rotation;
    }
    
    @Nonnull
    public static AssetIconProperties deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final AssetIconProperties obj = new AssetIconProperties();
        final byte nullBits = buf.getByte(offset);
        obj.scale = buf.getFloatLE(offset + 1);
        if ((nullBits & 0x1) != 0x0) {
            obj.translation = Vector2f.deserialize(buf, offset + 5);
        }
        if ((nullBits & 0x2) != 0x0) {
            obj.rotation = 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.translation != null) {
            nullBits |= 0x1;
        }
        if (this.rotation != null) {
            nullBits |= 0x2;
        }
        buf.writeByte(nullBits);
        buf.writeFloatLE(this.scale);
        if (this.translation != null) {
            this.translation.serialize(buf);
        }
        else {
            buf.writeZero(8);
        }
        if (this.rotation != null) {
            this.rotation.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 AssetIconProperties clone() {
        final AssetIconProperties copy = new AssetIconProperties();
        copy.scale = this.scale;
        copy.translation = ((this.translation != null) ? this.translation.clone() : null);
        copy.rotation = ((this.rotation != null) ? this.rotation.clone() : null);
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final AssetIconProperties other) {
            return this.scale == other.scale && Objects.equals(this.translation, other.translation) && Objects.equals(this.rotation, other.rotation);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.scale, this.translation, this.rotation);
    }
}
