package com.jscape.inet.ssh.protocol.v2.messages;

import com.jscape.inet.ssh.protocol.messages.Message;
import com.jscape.util.HexFormat;
import com.jscape.util.net.connection.MessageConnection;

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

/**
 * @author Alex Usun
 */
public class SshMsgChannelOpenUnknown
        extends SshMsgChannelOpen<SshMsgChannelOpenUnknown.Handler> {

    public final String channelType;
    public final byte[] data;

    public SshMsgChannelOpenUnknown(String channelType, int senderChannel, long initialWindowSize, int maxPacketSize, byte[] data) {
        super(senderChannel, initialWindowSize, maxPacketSize);

        assertNotNull(channelType);
        this.channelType = channelType;

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

    @Override
    public Class handlerClass() {
        return Handler.class;
    }

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

    @Override
    public String toString() {
        return "SshMsgChannelOpenUnknown {"
               + "channelType='" + this.channelType + '\''
               + ", senderChannel=" + this.senderChannel
               + ", initialWindowSize=" + this.initialWindowSize
               + ", maxPacketSize=" + this.maxPacketSize
               + ", data=" + HexFormat.formatData(this.data)
               + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

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

    }
}
