package com.jscape.inet.scp.events;

import com.jscape.inet.scp.Scp;

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

/**
 * SCP transfer progress event.
 *
 * @author Alex Usun
 */
public class ScpTransferProgressEvent
        extends ScpEvent {

    /**
     * Indicates UPLOAD process
     */
    public static final int UPLOAD = 0;

    /**
     * Indicates DOWNLOAD process
     */
    public static final int DOWNLOAD = 1;

    private final String filename;
    private final long transferredBytes;
    private final long size;
    private final int mode;

    /**
     * Creates a new event instance.
     *
     * @param source      source
     * @param filename    filename
     * @param transferred transferred bytes count
     * @param size        total size in bytes
     * @param mode        transfer mode
     */
    public ScpTransferProgressEvent(Scp source, String filename, long transferred, long size, int mode) {
        super(source);

        assertNotNull(filename);
        this.filename = filename;

        this.transferredBytes = transferred;
        this.size = size;
        this.mode = mode;
    }

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

    /**
     * Returns transferred bytes count.
     *
     * @return transferred bytes count
     */
    public long getTransferredBytes() {
        return this.transferredBytes;
    }

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

    /**
     * Returns transfer mode.
     *
     * @return transfer mode
     */
    public int getMode() {
        return this.mode;
    }

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

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