package com.jscape.inet.scp.events;

import com.jscape.inet.scp.Scp;

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

/**
 * SCP file downloaded event.
 *
 * @author Alex Usun
 */
public class ScpFileDownloadedEvent
        extends ScpEvent {

    private final String filename;
    private final long size;
    private final long time;

    /**
     * Creates a new event.
     *
     * @param source   source
     * @param filename file name
     * @param size     file size
     * @param time     transfer time
     */
    public ScpFileDownloadedEvent(Scp source, String filename, long size, long time) {
        super(source);

        assertNotNull(filename);
        this.filename = filename;

        this.size = size;
        this.time = time;
    }

    /**
     * Returns file name.
     *
     * @return file name
     */
    public String getFilename() {
        return this.filename;
    }

    /**
     * Returns file size in bytes.
     *
     * @return file size in bytes
     */
    public long getSize() {
        return this.size;
    }

    /**
     * Returns transfer time in milliseconds.
     *
     * @return transfer time in milliseconds
     */
    public long getTime() {
        return this.time;
    }

    /**
     * @see com.jscape.inet.scp.events.ScpEvent#accept(com.jscape.inet.scp.events.ScpEventListener)
     */
    public void accept(ScpEventListener listener) {
        listener.download(this);
    }

    @Override
    public String toString() {
        return "ScpFileDownloadedEvent {"
               + "filename='" + this.filename + '\''
               + ", size=" + this.size
               + ", time=" + this.time
               + '}';
    }
}
