// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.protocol.packets.camera;

import java.util.Objects;
import com.hypixel.hytale.protocol.io.ValidationResult;
import io.netty.buffer.ByteBuf;
import javax.annotation.Nonnull;
import com.hypixel.hytale.protocol.AccumulationMode;
import com.hypixel.hytale.protocol.Packet;

public class CameraShakeEffect implements Packet
{
    public static final int PACKET_ID = 281;
    public static final boolean IS_COMPRESSED = false;
    public static final int NULLABLE_BIT_FIELD_SIZE = 0;
    public static final int FIXED_BLOCK_SIZE = 9;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 9;
    public static final int MAX_SIZE = 9;
    public int cameraShakeId;
    public float intensity;
    @Nonnull
    public AccumulationMode mode;
    
    @Override
    public int getId() {
        return 281;
    }
    
    public CameraShakeEffect() {
        this.mode = AccumulationMode.Set;
    }
    
    public CameraShakeEffect(final int cameraShakeId, final float intensity, @Nonnull final AccumulationMode mode) {
        this.mode = AccumulationMode.Set;
        this.cameraShakeId = cameraShakeId;
        this.intensity = intensity;
        this.mode = mode;
    }
    
    public CameraShakeEffect(@Nonnull final CameraShakeEffect other) {
        this.mode = AccumulationMode.Set;
        this.cameraShakeId = other.cameraShakeId;
        this.intensity = other.intensity;
        this.mode = other.mode;
    }
    
    @Nonnull
    public static CameraShakeEffect deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final CameraShakeEffect obj = new CameraShakeEffect();
        obj.cameraShakeId = buf.getIntLE(offset + 0);
        obj.intensity = buf.getFloatLE(offset + 4);
        obj.mode = AccumulationMode.fromValue(buf.getByte(offset + 8));
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 9;
    }
    
    @Override
    public void serialize(@Nonnull final ByteBuf buf) {
        buf.writeIntLE(this.cameraShakeId);
        buf.writeFloatLE(this.intensity);
        buf.writeByte(this.mode.getValue());
    }
    
    @Override
    public int computeSize() {
        return 9;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 9) {
            return ValidationResult.error("Buffer too small: expected at least 9 bytes");
        }
        return ValidationResult.OK;
    }
    
    public CameraShakeEffect clone() {
        final CameraShakeEffect copy = new CameraShakeEffect();
        copy.cameraShakeId = this.cameraShakeId;
        copy.intensity = this.intensity;
        copy.mode = this.mode;
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final CameraShakeEffect other) {
            return this.cameraShakeId == other.cameraShakeId && this.intensity == other.intensity && Objects.equals(this.mode, other.mode);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.cameraShakeId, this.intensity, this.mode);
    }
}
