#ifndef SIMPLELOG_H
#define SIMPLELOG_H

#include <Windows.h>
#include <shlwapi.h>

#include <thread>
#include <mutex>

#include <iostream>
#include <cstring>
#include <limits>
#include <sstream>
#include <stdexcept>
#include <fstream>

void addLogStr(std::string str);

class SimpleLog
{
public:
    static SimpleLog *Instance();

    enum SaveTimeSpan
    {
        Month,
        Day,
        Hour,
        Minute
    };

    void setSavePath(std::string path);
    std::string savePath();

    void addLogTxt(std::string txt);

    void setShowTime(bool show);

    void setSaveTimeSpan(SaveTimeSpan span);

protected:
    SimpleLog();
    ~SimpleLog();

private:
    /**
     *@brief 检查资源目录或者文件是否存圿
     **/
    void checkResource();

private:
    static SimpleLog *mInstance;
    static std::mutex mMutex;

    SaveTimeSpan mSaveTimeSpan;
    std::string mSaveDir;
    std::string mSaveFileName;

    std::string mSavePath;

    std::ofstream out;
    bool mShowTime;

    // GC籿
    // 程序退出后，该类的析构函数释放单例内存
    class GC
    {
    public:
        ~GC()
        {
            if (mInstance != nullptr)
            {
                delete mInstance;
                mInstance = nullptr;
            }
        }
    };

    static GC gc;
};

#endif // SIMPLELOG_H
