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 SshMsgChannelRequestExec
        extends SshMsgChannelRequest<SshMsgChannelRequestExec.Handler> {

    public final String command;

    public SshMsgChannelRequestExec(int recipientChannel, boolean wantReply, String command) {
        super(recipientChannel, wantReply);

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

    @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 "SshMsgChannelRequestExec {"
                + "recipientChannel=" + this.recipientChannel
                + ", wantReply=" + this.wantReply
                + ", command='" + this.command + '\''
                + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

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

    }
}
