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 SshMsgChannelOpenFailure
        extends Message<SshMsgChannelOpenFailure.Handler> {

    public final int recipientChannel;
    public final int reasonCode;
    public final String description;
    public final String languageTag;

    public SshMsgChannelOpenFailure(int recipientChannel, int reasonCode, String description, String languageTag) {
        this.recipientChannel = recipientChannel;
        this.reasonCode = reasonCode;

        assertNotNull(description);
        this.description = description;

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

    public SshMsgChannelOpenFailure(int recipientChannel, ChannelOpenFailureReason reason, String description, String languageTag) {
        this(recipientChannel, reason.code, description, languageTag);
    }

    @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 "SshMsgChannelOpenFailure {"
                + "recipientChannel=" + this.recipientChannel
                + ", reasonCode=" + this.reasonCode
                + ", description='" + this.description + '\''
                + ", languageTag='" + this.languageTag + '\''
                + '}';
    }

    public interface Handler
            extends Message.HandlerBase {

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

    }
}
