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.assertGreaterOrEqual;

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

    public final int recipientChannel;
    public final long bytesToAdd;

    public SshMsgChannelWindowAdjust(int recipientChannel, long bytesToAdd) {
        this.recipientChannel = recipientChannel;

        assertGreaterOrEqual(bytesToAdd, 0, "Bad bytes to add value.");
        this.bytesToAdd = bytesToAdd;
    }

    @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 "SshMsgChannelWindowAdjust {"
                + "recipientChannel=" + this.recipientChannel
                + ", bytesToAdd=" + this.bytesToAdd
                + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

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

    }
}
