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

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

import java.util.List;

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

/**
 * @author Alex Usun
 */
public class SshMsgChannelRequestPtyReq
        extends SshMsgChannelRequest<SshMsgChannelRequestPtyReq.Handler> {

    public final String terminalEnvironmentVariable;
    public final int terminalCharactersWidth;
    public final int terminalRowsHeight;
    public final int terminalPixelsWidth;
    public final int terminalPixelsHeight;
    public final List<TerminalMode> terminalModes;

    public SshMsgChannelRequestPtyReq(int recipientChannel,
                                      boolean wantReply,
                                      String terminalEnvironmentVariable,
                                      int terminalCharactersWidth,
                                      int terminalRowsHeight,
                                      int terminalPixelsWidth,
                                      int terminalPixelsHeight,
                                      List<TerminalMode> terminalModes) {
        super(recipientChannel, wantReply);

        assertNotNull(terminalEnvironmentVariable);
        this.terminalEnvironmentVariable = terminalEnvironmentVariable;

        this.terminalCharactersWidth = terminalCharactersWidth;
        this.terminalRowsHeight = terminalRowsHeight;
        this.terminalPixelsWidth = terminalPixelsWidth;
        this.terminalPixelsHeight = terminalPixelsHeight;

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

    @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 "SshMsgChannelRequestPtyReq {"
                + "recipientChannel=" + this.recipientChannel
                + ", wantReply=" + this.wantReply
                + ", terminalEnvironmentVariable='" + this.terminalEnvironmentVariable + '\''
                + ", terminalCharactersWidth=" + this.terminalCharactersWidth
                + ", terminalRowsHeight=" + this.terminalRowsHeight
                + ", terminalPixelsWidth=" + this.terminalPixelsWidth
                + ", terminalPixelsHeight=" + this.terminalPixelsHeight
                + ", terminalModes=" + this.terminalModes
                + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

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

    }
}
