#ifndef CLOGTRACK_H
#define CLOGTRACK_H

#include <list>
#include <QString>
#include <map>
#include <thread>
#include <mutex>

#include <QWidget>

#include "CHttpClient.h"

namespace LOG_CONSTANT_DEF
{
    const char* const LOG_API_VERSION = "0.6.0";
    const char* const X_LOG_APIVERSION = "x-log-apiversion";
    const char* const X_LOG_BODYRAWSIZE = "x-log-bodyrawsize";
    const char* const SOURCE = "__source__";
    const char* const WIN = "win";
    const char* const LOGS = "__logs__";
};

struct OC
{
    OC() { oc = std::make_shared<std::once_flag >();}
    std::shared_ptr<std::once_flag> oc;
    int a;
};

class CLogInfo
{
public:
    QString sKey;
    QString sValue;
    CLogInfo()
    {
        sKey = "";
        sValue = "";
    }
};

class CLogData
{
public:
    CLogData();
    ~CLogData();
    QString genLogJson();
    void pushLog(QString sKey, QString sValue);
private:
    std::vector<CLogInfo> m_LogList;
};

class CLogTrack : public QObject
{
    Q_OBJECT

public:
    CLogTrack(QString sProjectName, QString sEndpoint, QString sLogstore);
    ~CLogTrack();

    void putLog(CLogData log);
signals:
   // void logFaild(OC oc);
private:
    void threadProc();

    std::thread m_thread;
    bool m_bIsRun;

    std::list<CLogData> m_LogList;
    std::mutex m_logMutex;

    CHttpClient m_httpClient;

    QString m_sUrl;
};

extern std::shared_ptr<CLogTrack> g_logPtr;

//class base : public QWidget
//{
//    Q_OBJECT
//public:
//    base(QWidget *parent = nullptr) : QWidget(parent)
//    {
//        qRegisterMetaType<OC>("OC");
//        connect(g_logPtr.get(), &CLogTrack::logFaild, this, &base::logFaild);
//    }
//private slots:
//    virtual void logFaild(OC oc)
//    {
//        std::call_once(*oc.oc.get(), []() {

//        });
//    }

//};



#endif // CLOGTRACK_H
