package com.jscape.inet.sftp.protocol.messages;

import com.jscape.util.net.connection.MessageConnection;

import java.util.Arrays;

import static com.jscape.util.Parameters.assertNotNull;

/**
 * @author Alex Usun
 */
public class UnknownMessage
        extends Message<UnknownMessage.Handler> {

    public final int messageType;
    public final int id;
    public final byte[] data;

    public UnknownMessage(int messageType, int id, byte[] data) {
        this.messageType = messageType;
        this.id = id;

        assertNotNull(data);
        this.data = data;
    }

    @Override
    public void accept(Handler handler, MessageConnection<Message> connection) {
        handler.handle(this, connection);
    }

    @Override
    public String toString() {
        return "UnknownMessage {"
                + "messageType=" + this.messageType
                + ", id=" + this.id
                + ", data=" + Arrays.toString(this.data)
                + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

        void handle(UnknownMessage message, MessageConnection<Message> connection);

    }
}
