#ifndef LOGGER_H
#define LOGGER_H

#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include <QMutex>
#include <QString>
#include <QScopedPointer>

class Logger
{
public:
    enum LogLevel {
        Debug,
        Info,
        Warning,
        Error,
        Critical
    };

    // Public static method to get the single instance of the Logger
    static Logger& getInstance(const QString &filePath = "");

    // Direct logging methods
    void debug(const QString &message);
    void info(const QString &message);
    void warn(const QString &message);
    void error(const QString &message);
    void critical(const QString &message);

    void setMaxFileSize(qint64 bytes);
    void setMaxBackupFiles(int count);

    // Make the destructor public so QScopedPointer can call it
    ~Logger(); // <-- CHANGE THIS LINE: MOVED FROM PRIVATE TO PUBLIC

private:
    // Private constructor to prevent direct instantiation
    explicit Logger(const QString &filePath);

    // Delete copy constructor and assignment operator to prevent copying
    Logger(const Logger&) = delete;
    Logger& operator=(const Logger&) = delete;

    QFile m_logFile;
    QTextStream m_textStream;
    QMutex m_mutex;
    qint64 m_maxFileSize;
    int m_maxBackupFiles;

    void writeLog(LogLevel level, const QString &message);
    void rotateLogFile();
    QString logLevelToString(LogLevel level) const;

    // Static members for the singleton instance
    static QScopedPointer<Logger> m_instance;
    static QMutex m_instanceMutex;
};

#endif // LOGGER_H
