/*
 * @(#)SftpProgressEvent.java
 *
 * Copyright (c) 2001-2004 JScape
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JScape. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JScape.
 */
package com.jscape.inet.sftp.events;

import com.jscape.inet.sftp.Sftp;

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

/**
 * This event is fired on significant progress in upload and
 * download operations in Sftp class.
 */
public class SftpProgressEvent
        extends SftpEvent {

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

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

    private final String fileName;
    private final String path;
    private final String localFilePath;
    private final int mode;
    private final long totalBytes;
    private final long transferredBytes;

    public SftpProgressEvent(Sftp source, String fileName, String path, String localFilePath, int mode, long totalBytes, long transferredBytes) {
        super(source);

        assertNotNull(fileName);
        this.fileName = fileName;

        this.path = path;
        this.localFilePath = localFilePath;
        this.mode = mode;
        this.totalBytes = totalBytes;
        this.transferredBytes = transferredBytes;
    }

    /**
     * Gets the name of file transferred.
     *
     * @return the name of file transferred
     */
    public String getFilename() {
        return this.fileName;
    }

    /**
     * Get path.
     *
     * @return path
     */
    public String getPath() {
        return this.path;
    }

    /**
     * Get local file path,
     *
     * @return path.
     */
    public String getLocalFilePath() {
        return this.localFilePath;
    }

    /**
     * Gets mode of transfer, upload or download.
     *
     * @return transfer mode
     *
     * @see #UPLOAD
     * @see #DOWNLOAD
     */
    public int getMode() {
        return this.mode;
    }

    /**
     * Gets the number of bytes transferred so far.
     *
     * @return the number of bytes transferred
     */
    public long getBytes() {
        return this.transferredBytes;
    }

    /**
     * Gets the total number of bytes for the file being transferred.
     *
     * @return the total number of bytes for the file
     */
    public long getTotalBytes() {
        return this.totalBytes;
    }

    /**
     * The "backwards dispatching" support.
     *
     * @param listener the event listener
     */
    public void accept(SftpListener listener) {
        listener.progress(this);
    }

}
