package net.md_5.bungee.protocol.packet;

import io.netty.buffer.ByteBuf;

import java.util.Arrays;

public class PacketFCEncryptionResponse extends DefinedPacket
{

    private byte[] sharedSecret;
    private byte[] verifyToken;

    private PacketFCEncryptionResponse()
    {
        super( 0xFC );
    }

    public PacketFCEncryptionResponse(byte[] sharedSecret, byte[] verifyToken)
    {
        this();
        this.sharedSecret = sharedSecret;
        this.verifyToken = verifyToken;
    }

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

    public byte[] getSharedSecret(){
        return sharedSecret;
    }

    @Override
    public void read(ByteBuf buf)
    {
        sharedSecret = readArray( buf );
        verifyToken = readArray( buf );
    }

    @Override
    public void write(ByteBuf buf)
    {
        writeArray( sharedSecret, buf );
        writeArray( verifyToken, buf );
    }

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

    @Override
    public String toString() {
        return "PacketFCEncryptionResponse(sharedSecret=" + Arrays.toString(this.getSharedSecret()) + ", verifyToken=" + Arrays.toString(this.getVerifyToken()) + ")";
    }

    @Override
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof PacketFCEncryptionResponse)) {
            return false;
        }
        final PacketFCEncryptionResponse other = (PacketFCEncryptionResponse) o;
        return other.canEqual(this) && Arrays.equals(this.getSharedSecret(), other.getSharedSecret()) && Arrays.equals(this.getVerifyToken(), other.getVerifyToken());
    }

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

    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = result * 31 + Arrays.hashCode(this.getSharedSecret());
        result = result * 31 + Arrays.hashCode(this.getVerifyToken());
        return result;
    }
}
