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

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

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

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

    public final String host;
    public final int port;
    public final String originatorAddress;
    public final int originatorPort;

    public SshMsgChannelOpenDirectTcpIp(int senderChannel, long initialWindowSize, int maxPacketSize, String host, int port, String originatorAddress, int originatorPort) {
        super(senderChannel, initialWindowSize, maxPacketSize);

        assertNotNull(host);
        this.host = host;

        this.port = port;

        assertNotNull(originatorAddress);
        this.originatorAddress = originatorAddress;

        this.originatorPort = originatorPort;
    }

    @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 "SshMsgChannelOpenDirectTcpIp {"
               + "senderChannel=" + this.senderChannel
               + ", initialWindowSize=" + this.initialWindowSize
               + ", maxPacketSize=" + this.maxPacketSize
               + ", host='" + this.host + '\''
               + ", port=" + this.port
               + ", originatorAddress='" + this.originatorAddress + '\''
               + ", originatorPort=" + this.originatorPort
               + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

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

    }
}
