#ifndef DOWNLOADMANAGER_H
#define DOWNLOADMANAGER_H

#include <QObject>
#include <QtNetwork>

class DownloadManager : public QObject
{
    Q_OBJECT
public:
    explicit DownloadManager(QObject *parent = nullptr);
    void createNetworkAccessManager();
    static QString getSaveFilePath(const QUrl &url);
    static bool isHttpRedirect(QNetworkReply *reply);

Q_SIGNALS:
    void finished(const QString& filepath);

public Q_SLOTS:
    void doDownload(const QUrl &url);
    void onFinished();

    void saveFile (qint64 received, qint64 total);
    void calculateSizes (qint64 received, qint64 total);
    void updateProgress (qint64 received, qint64 total);
    void calculateTimeRemaining (qint64 received, qint64 total);

private:
    QNetworkAccessManager* m_manager = nullptr;
    QNetworkReply* m_reply = nullptr;
    uint m_startTime = 0;
    QString m_filePath;
};

#endif // DOWNLOADMANAGER_H
