#pragma once

#include <QObject>
#include <QJsonObject>
#include <QScopedPointer>
#include <QNetworkReply>
#include <curl/curl.h>

class UserInfo;

class LegalizationAgentPrivate;
class LegalizationAgent : public QObject
{
    Q_OBJECT
public:
    explicit LegalizationAgent(QObject *parent = Q_NULLPTR);
    ~LegalizationAgent();

    void initConnect();

    void saveUserData(const UserInfo &userInfo);

    void saveSoftwareUsedHistory(const QByteArray &data);
    void loadSoftwareUsedHistory();

    void updateSystemInfo(const UserInfo &userInfo);
    QJsonObject pushSystemInfoByCurl();

public Q_SLOTS:
    void startServer();
    void postSystemInfo();
    void postlog();
    void onDownloadFinished(const QString &filePath);
    void cacheSoftwareInfo();

    Q_INVOKABLE void ReportUserInfo(const QString &jsonStr);
    Q_INVOKABLE void RegisterClientPort(const int &port);
    Q_INVOKABLE QString QuerySystemInfo();
    Q_INVOKABLE QString QueryAreacode();
    Q_INVOKABLE QString QueryOrgcode();
    Q_INVOKABLE QMap<QString, QString> QueryOrgcodes();
    Q_INVOKABLE QString QueryApiURL();
    Q_INVOKABLE QStringList QueryCityNames();
    Q_INVOKABLE QJsonObject QueryUserInfo();
    Q_INVOKABLE QString SubmitSystemInfo(QByteArray userInfoJson);
    Q_INVOKABLE QString GetQrMessage(QByteArray userInfoJson);

private:
    QScopedPointer<LegalizationAgentPrivate> dd_ptr;
    Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), LegalizationAgent)
};

