package net.md_5.bungee.protocol.packet;

import io.netty.buffer.ByteBuf;

import java.util.Arrays;

public class PacketFDEncryptionRequest extends DefinedPacket
{

    private String serverId;
    private byte[] publicKey;
    private byte[] verifyToken;

    private PacketFDEncryptionRequest()
    {
        super( 0xFD );
    }

    public byte[] getVerifyToken(){
        return verifyToken;
    }

    public byte[] getPublicKey(){
        return publicKey;
    }

    public String getServerId(){
        return serverId;
    }

    public PacketFDEncryptionRequest(String serverId, byte[] publicKey, byte[] verifyToken)
    {
        this();
        this.serverId = serverId;
        this.publicKey = publicKey;
        this.verifyToken = verifyToken;
    }

    @Override
    public void read(ByteBuf buf)
    {
        serverId = readString( buf );
        publicKey = readArray( buf );
        verifyToken = readArray( buf );
    }

    @Override
    public void write(ByteBuf buf)
    {
        writeString( serverId, buf );
        writeArray( publicKey, buf );
        writeArray( verifyToken, buf );
    }

    @Override
    public void handle(AbstractPacketHandler handler) throws Exception
    {
        handler.handle( this );
    }

    @Override
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof PacketFDEncryptionRequest)) {
            return false;
        }
        final PacketFDEncryptionRequest other = (PacketFDEncryptionRequest) o;
        if (!other.canEqual(this)) {
            return false;
        }
        final Object this$serverId = this.getServerId();
        final Object other$serverId = other.getServerId();
        if (this$serverId == null) {
            if (other$serverId == null) {
                return Arrays.equals(this.getPublicKey(), other.getPublicKey()) && Arrays.equals(this.getVerifyToken(), other.getVerifyToken());
            }
        } else if (this$serverId.equals(other$serverId)) {
            return Arrays.equals(this.getPublicKey(), other.getPublicKey()) && Arrays.equals(this.getVerifyToken(), other.getVerifyToken());
        }
        return false;
    }

    public boolean canEqual(final Object other) {
        return other instanceof PacketFDEncryptionRequest;
    }

    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        final Object $serverId = this.getServerId();
        result = result * 31 + (($serverId == null) ? 0 : $serverId.hashCode());
        result = result * 31 + Arrays.hashCode(this.getPublicKey());
        result = result * 31 + Arrays.hashCode(this.getVerifyToken());
        return result;
    }

    @Override
    public String toString() {
        return "PacketFDEncryptionRequest(serverId=" + this.getServerId() + ", publicKey=" + Arrays.toString(this.getPublicKey()) + ", verifyToken=" + Arrays.toString(this.getVerifyToken()) + ")";
    }
}
