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

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

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.Packet;

public class UpdateTimeSettings implements Packet
{
    public static final int PACKET_ID = 145;
    public static final boolean IS_COMPRESSED = false;
    public static final int NULLABLE_BIT_FIELD_SIZE = 0;
    public static final int FIXED_BLOCK_SIZE = 10;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 10;
    public static final int MAX_SIZE = 10;
    public int daytimeDurationSeconds;
    public int nighttimeDurationSeconds;
    public byte totalMoonPhases;
    public boolean timePaused;
    
    @Override
    public int getId() {
        return 145;
    }
    
    public UpdateTimeSettings() {
    }
    
    public UpdateTimeSettings(final int daytimeDurationSeconds, final int nighttimeDurationSeconds, final byte totalMoonPhases, final boolean timePaused) {
        this.daytimeDurationSeconds = daytimeDurationSeconds;
        this.nighttimeDurationSeconds = nighttimeDurationSeconds;
        this.totalMoonPhases = totalMoonPhases;
        this.timePaused = timePaused;
    }
    
    public UpdateTimeSettings(@Nonnull final UpdateTimeSettings other) {
        this.daytimeDurationSeconds = other.daytimeDurationSeconds;
        this.nighttimeDurationSeconds = other.nighttimeDurationSeconds;
        this.totalMoonPhases = other.totalMoonPhases;
        this.timePaused = other.timePaused;
    }
    
    @Nonnull
    public static UpdateTimeSettings deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final UpdateTimeSettings obj = new UpdateTimeSettings();
        obj.daytimeDurationSeconds = buf.getIntLE(offset + 0);
        obj.nighttimeDurationSeconds = buf.getIntLE(offset + 4);
        obj.totalMoonPhases = buf.getByte(offset + 8);
        obj.timePaused = (buf.getByte(offset + 9) != 0);
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 10;
    }
    
    @Override
    public void serialize(@Nonnull final ByteBuf buf) {
        buf.writeIntLE(this.daytimeDurationSeconds);
        buf.writeIntLE(this.nighttimeDurationSeconds);
        buf.writeByte(this.totalMoonPhases);
        buf.writeByte(this.timePaused ? 1 : 0);
    }
    
    @Override
    public int computeSize() {
        return 10;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 10) {
            return ValidationResult.error("Buffer too small: expected at least 10 bytes");
        }
        return ValidationResult.OK;
    }
    
    public UpdateTimeSettings clone() {
        final UpdateTimeSettings copy = new UpdateTimeSettings();
        copy.daytimeDurationSeconds = this.daytimeDurationSeconds;
        copy.nighttimeDurationSeconds = this.nighttimeDurationSeconds;
        copy.totalMoonPhases = this.totalMoonPhases;
        copy.timePaused = this.timePaused;
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final UpdateTimeSettings other) {
            return this.daytimeDurationSeconds == other.daytimeDurationSeconds && this.nighttimeDurationSeconds == other.nighttimeDurationSeconds && this.totalMoonPhases == other.totalMoonPhases && this.timePaused == other.timePaused;
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.daytimeDurationSeconds, this.nighttimeDurationSeconds, this.totalMoonPhases, this.timePaused);
    }
}
