#ifndef TCHTTPSERVICE_H
#define TCHTTPSERVICE_H

#define DEBUG 1

#include <QObject>
#include <QNetworkAccessManager>
#include <QUrlQuery>
#include <QCryptographicHash>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonObject>
#include <QJsonArray>
#include <QFile>
#include <QFileInfo>
#include <QHttpMultiPart>
#include <QHttpPart>
#include <QHttpMultiPart>

class TCHttpService : public QObject
{
    Q_OBJECT
private:
    typedef struct {
        QString file_name;
        int share_status;
        QString url;
        qint64 size;
    } file_info_t;

    QMap<QString, file_info_t> m_fileMap;
public:
    static TCHttpService* getInstance();

    void apiLogin();
    void apiMyfileCount();
    void apiMyfileNormal(int start, int count);
    void apiMd5(const QString& filePath);
    void apiUpload(const QString& filePath);
    void apiSharePicShare(const QString& fileName, const QString& md5);
    void setConfiguration(QString userName, QString firstPwd, QString domain);
    void setSsl(bool enable);
    bool getOnlineState();
    void setUploadNum(int nb);

private:

    QUrl encodeUrl(QString url, QMap<QString, QString> params);
    void updateFileMap(QJsonObject jsonObj);
signals:
    void signal_loginSuc();
    void signal_uploadSuc();
    void signal_shareSuc();
    void signal_uploadFileSec(QString url);
    void requestFinished(QNetworkReply* reply, QString api);
private:
    explicit TCHttpService(QObject *parent = nullptr);

    static QScopedPointer<TCHttpService> m_instance;

    QNetworkAccessManager m_manager;

    QString m_token;
    QString m_domain;
    QString m_firstPwd;
    QString m_userName;
    int m_total;
    bool m_enableSsl = true;

    bool m_isOnline = false;

    bool m_uploadNum = 0;

};

#endif // TCHTTPSERVICE_H
