#ifndef LOGGER_H
#define LOGGER_H

#include <QPlainTextEdit>
#include <QDateTime>
#include <QMutex>
#include <QObject>
#include <QDebug>
#include <QDir>
#include "Systems/tools.h"

enum LogLevel
{
    INFO,
    WARNING,
    ERROR,
    CRITICAL,
    DEBUG
};

enum LoggingType
{
    WIDGET,
    CONSOLE,
    TOFILE
};

class Logger : public QObject
{
    Q_OBJECT

public:
    Logger();
    static Logger& instance();
    ~Logger();
    void setWidget(QPlainTextEdit * widget);
    void setLoggingType(LoggingType type);
    void log(QString message,LogLevel level = INFO);
    void setLogFile(QString filePath);
    void setLogToFile(bool flag);

public slots:
    void handleLog(QString msg,LogLevel logLevel = INFO);

signals:
    void sigAddToLogger(QString msg, LogLevel logLevel = INFO);
    void sigLogToWidget(QString message);

private:
    QString msg;
    QFile logFile;
    LoggingType loggingType;
    QMutex mutex;
    bool isLogToFile;

    void createDirectory();
};

#endif // LOGGER_H
