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

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

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 RequestServerAccess implements Packet
{
    public static final int PACKET_ID = 250;
    public static final boolean IS_COMPRESSED = false;
    public static final int NULLABLE_BIT_FIELD_SIZE = 0;
    public static final int FIXED_BLOCK_SIZE = 3;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 3;
    public static final int MAX_SIZE = 3;
    @Nonnull
    public Access access;
    public short externalPort;
    
    @Override
    public int getId() {
        return 250;
    }
    
    public RequestServerAccess() {
        this.access = Access.Private;
    }
    
    public RequestServerAccess(@Nonnull final Access access, final short externalPort) {
        this.access = Access.Private;
        this.access = access;
        this.externalPort = externalPort;
    }
    
    public RequestServerAccess(@Nonnull final RequestServerAccess other) {
        this.access = Access.Private;
        this.access = other.access;
        this.externalPort = other.externalPort;
    }
    
    @Nonnull
    public static RequestServerAccess deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final RequestServerAccess obj = new RequestServerAccess();
        obj.access = Access.fromValue(buf.getByte(offset + 0));
        obj.externalPort = buf.getShortLE(offset + 1);
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 3;
    }
    
    @Override
    public void serialize(@Nonnull final ByteBuf buf) {
        buf.writeByte(this.access.getValue());
        buf.writeShortLE(this.externalPort);
    }
    
    @Override
    public int computeSize() {
        return 3;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 3) {
            return ValidationResult.error("Buffer too small: expected at least 3 bytes");
        }
        return ValidationResult.OK;
    }
    
    public RequestServerAccess clone() {
        final RequestServerAccess copy = new RequestServerAccess();
        copy.access = this.access;
        copy.externalPort = this.externalPort;
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final RequestServerAccess other) {
            return Objects.equals(this.access, other.access) && this.externalPort == other.externalPort;
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.access, this.externalPort);
    }
}
