/*
 * @(#)FileTransferProgressEvent.java
 *
 * Copyright (c) 1999-2007 JSCAPE LLC
 *
 * 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.filetransfer;

/**
 * Fired on significant progress in upload and download operations in
 * <code>FileTransfer</code> derived classes.
 */
public class FileTransferProgressEvent
        extends FileTransferEvent {

    public static final int UPLOAD = 0;
    public static final int DOWNLOAD = 1;

    private final String filename;
    private final String absolutePath;
    private final String localFilePath;
    private final int mode;
    private final long bytes;
    private final long totalBytes;
    private final long readBytes;

    /**
     * Creates a new event instance.
     *
     * @param source
     * @param filename
     * @param absolutePath
     * @param localFilePath
     * @param mode
     * @param bytes
     * @param readBytes
     * @param totalBytes
     */
    public FileTransferProgressEvent(FileTransfer source,
                                     String filename,
                                     String absolutePath,
                                     String localFilePath,
                                     int mode,
                                     long bytes,
                                     long readBytes,
                                     long totalBytes) {
        super(source);

        this.filename = filename;
        this.absolutePath = absolutePath;
        this.localFilePath = localFilePath;
        this.mode = mode;
        this.bytes = bytes;
        this.readBytes = readBytes;
        this.totalBytes = totalBytes;
    }

    /**
     * Constructs new <code>FileTransferProgressEvent</code>.
     *
     * @param source       the source of this event
     * @param filename     the name of file being transferred
     * @param absolutePath the file path of file transferred
     * @param mode         the direction of transfer
     * @param bytes        the number of bytes transferred
     * @param totalBytes   the number of bytes for the file being transferred
     */
    public FileTransferProgressEvent(FileTransfer source,
                                     String filename,
                                     String absolutePath,
                                     int mode,
                                     long bytes,
                                     long totalBytes) {
        this(source, filename, absolutePath, "", mode, bytes, 0, totalBytes);
    }

    /**
     * Constructor.
     *
     * @param source
     * @param filename
     * @param absolutePath
     * @param mode
     * @param bytes
     * @param readBytes
     * @param totalBytes
     */
    public FileTransferProgressEvent(FileTransfer source,
                                     String filename,
                                     String absolutePath,
                                     int mode,
                                     long bytes,
                                     long readBytes,
                                     long totalBytes) {
        this(source, filename, absolutePath, "", mode, bytes, readBytes, totalBytes);
    }

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

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


    /**
     * Returns number of read bytes.
     *
     * @return a number of read bytes
     */
    public long getReadBytes() {
        return this.readBytes;
    }

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


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

    /**
     * Gets absolute path of file transferred.
     *
     * @return the absolute path
     */
    public String getAbsolutePath() {
        return this.absolutePath;
    }

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

    /**
     * {@inheritDoc}
     */
    public void accept(FileTransferListener listener) {
        listener.progress(this);
    }

    @Override
    public String toString() {
        return "FileTransferProgressEvent {"
                + "bytes=" + this.bytes
                + ", totalBytes=" + this.totalBytes
                + ", readBytes=" + this.readBytes
                + ", filename='" + this.filename + '\''
                + ", localFilePath='" + this.localFilePath + '\''
                + ", absolutePath='" + this.absolutePath + '\''
                + ", mode=" + this.mode
                + '}';
    }
}
