#include "AudioContext.h"

namespace UkuiAudioFramwork
{
AudioContext::AudioContext()
    : m_log(getLogPath(), "audio-service.log", EnumToInt(simple_logger::OutputType::Console) | EnumToInt(simple_logger::OutputType::LogFile))
{
    // 开启日志
    std::string name = getModuleName(getModule());
    m_log.AddModule(EnumToInt(getModule()), name);
    m_log.SetLogSwitchOn(simple_logger::LogLevel::Debug);
    m_log.SetOutputTypeOn(simple_logger::OutputType::LogFile);
    m_log.SetDetailMode(true);
}

AudioContext& AudioContext::getInstance()
{
    static AudioContext context;
    return context;
}

std::string AudioContext::getLogPath()
{
    const char* homeDir = getenv("HOME");
    if (homeDir == nullptr) {
        return std::string("ukui-volume-control/log/");
    }
    return std::string(homeDir) + "/.log/ukui-volume-control/log/";
}

simple_logger::Log& AudioContext::getLogger()
{
    return m_log;
}

Module AudioContext::getModule() const
{
    return m_module;
}
}
