package com.jscape.inet.scp.events;

import com.jscape.inet.scp.Scp;

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

/**
 * SCP connected event.
 *
 * @author Alex Usun
 */
public class ScpConnectedEvent
        extends ScpEvent {

    private final String host;
    private final int port;

    /**
     * Creates a new event instance.
     *
     * @param source source
     * @param host host
     * @param port port
     */
    public ScpConnectedEvent(Scp source, String host, int port) {
        super(source);

        assertNotNull(host);
        this.host = host;

        this.port = port;
    }

    /**
     * Returns connected host.
     *
     * @return connected host
     */
    public String getHost() {
        return this.host;
    }

    /**
     * Returns connected port.
     *
     * @return connected port
     */
    public int getPort() {
        return this.port;
    }

    /**
     * @see ScpEvent#accept(ScpEventListener)
     */
    public void accept(ScpEventListener listener) {
        listener.connected(this);
    }

    @Override
    public String toString() {
        return "ScpConnectedEvent {"
               + "host='" + this.host + '\''
               + ", port=" + this.port
               + '}';
    }
}
