#pragma once
#include <WinSock2.h>
#include<windows.h>
#include <ctime>

#include <string>
#include <sstream>
#include <iomanip>
#include <QDateTime>
#include <QMutex>

enum Log_Type
{
	Log_Type_Product,
	Log_Type_Info,
	Log_Type_Warning,
	Log_Type_Error
};

inline const char* LogTypeToStr(Log_Type logType){
	switch(logType){
	case Log_Type_Info:
		return " Info ";
		break;
	case Log_Type_Warning:
		return " Warn ";
		break;
	case Log_Type_Error:
		return " Err  ";
		break;
	case Log_Type_Product:
		return " PRO  ";
		break;
	default:
		return " Info ";
		break;
	}
}

struct _Tag_LOG
{
	_Tag_LOG(std::string msg, Log_Type type)
	{
		m_msg = msg;
		m_type = type;
		m_sType = LogTypeToStr(type);
		m_TimeStr = QDateTime::currentDateTime();
		//.toString("yyyy-MM-dd hh:mm:ss zzz").toStdString();
	}
	std::string m_msg;
	Log_Type m_type;
	QDateTime m_TimeStr;
	std::string m_sType;
};


class CRecordLog
{
public:
	CRecordLog();
	virtual ~CRecordLog();

	void AddLog(Log_Type type,const QString& msg);

	void LogInfo(const QString& msg);
	void LogError(const QString& msg);
	void ProductLog(const QString& msg);

	std::list<_Tag_LOG> m_LogVec;
	bool m_bRunning;

	HANDLE CreateThread();

	void	AutoWriteLog();//自动将m_LogVec内容写入文件
	void	Exit();
private:
	
	QMutex	 m_AWLogMutex;//添加&记录日志的锁

	QString GetFileNameByType(Log_Type type);
	QString CreateFilePathCurDate(const QString& parentFolder); //获取当前时间的日志文件名
	HANDLE m_ThreadHandle;
public:
	QString GetPicNameByCurTime(); //获取当前保存图片的文件名
};

//extern CRecordLog gRecordLog;
