#ifndef TCHTTPSERVICE_H
#define TCHTTPSERVICE_H

#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>

class TCHttpService : public QObject
{
    Q_OBJECT
public:
    static TCHttpService* getInstance();

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

private:

    QUrl encodeUrl(QString url, QMap<QString, QString> params);
    void updateFileMap(QJsonObject jsonObj);
signals:
    void signal_loginSuc();
    void signal_uploadSuc();
    void signal_shareSuc();

    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;
    QMap<QString, QString> m_fileMap;
    int m_total;
    bool m_enableSsl = true;

signals:

};

#endif // TCHTTPSERVICE_H
