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

    QNetworkReply* Get(const QUrl& url, const QMap<QString, QString> headers = {},
                       const QMap<QString, QString> params = {});
    QNetworkReply* Post(const QUrl& url, const QMap<QString, QString> headers = {},
                        const QMap<QString, QString> params = {}, const QByteArray body =QByteArray());

    QByteArray Post(QUrl url, QMap<QString, QString> headers = {},
                        QMap<QString, QString> params = {}, QByteArray body =QByteArray(), int i = 1);
    void updateFileMap(QJsonObject jsonObj);
signals:
    void signal_loginSuc();
    void signal_uploadSuc();
    void signal_shareSuc();

    void requestFinished(QNetworkReply* reply);
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
