#include "sidebar-main.h"
#include "log-utils.h"

namespace {
QStringList g_calls;
QString g_lastWidgetId;
bool g_lastShowReturnButton = false;
QString g_lastParsedMessage;

QString g_lastInitFileName;
int g_outputCallCount = 0;
}

SidebarMain::SidebarMain(QObject *parent) : QObject(parent)
{
    g_calls.append("construct");
}

void SidebarMain::requestWidgetActive(const QString &id, bool showReturnButton)
{
    g_calls.append("widget");
    g_lastWidgetId = id;
    g_lastShowReturnButton = showReturnButton;
}

void SidebarMain::resetRecords()
{
    g_calls.clear();
    g_lastWidgetId.clear();
    g_lastShowReturnButton = false;
    g_lastParsedMessage.clear();
}

QStringList SidebarMain::calls()
{
    return g_calls;
}

QString SidebarMain::lastWidgetId()
{
    return g_lastWidgetId;
}

bool SidebarMain::lastShowReturnButton()
{
    return g_lastShowReturnButton;
}

QString SidebarMain::lastParsedMessage()
{
    return g_lastParsedMessage;
}

void SidebarMain::parseMessage(const QString &msg)
{
    g_calls.append("parse:" + msg);
    g_lastParsedMessage = msg;
}

void SidebarMain::requestSidebar(SidebarMain::Request request)
{
    g_calls.append(QString("sidebar:%1").arg(static_cast<int>(request)));
}

void SidebarMain::requestShortcut(SidebarMain::Request request)
{
    g_calls.append(QString("shortcut:%1").arg(static_cast<int>(request)));
}

void SidebarMain::requestNotificationCenter(SidebarMain::Request request)
{
    g_calls.append(QString("notice:%1").arg(static_cast<int>(request)));
}

void LogUtils::initLogFile(const QString &fileName)
{
    g_lastInitFileName = fileName;
}

void LogUtils::messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    Q_UNUSED(type)
    Q_UNUSED(context)
    Q_UNUSED(msg)
    ++g_outputCallCount;
}

void LogUtils::reset()
{
    g_lastInitFileName.clear();
    g_outputCallCount = 0;
}

QString LogUtils::lastInitFileName()
{
    return g_lastInitFileName;
}

int LogUtils::outputCallCount()
{
    return g_outputCallCount;
}
