#include "AuthenticationHelper.h"

#include <QApplication>
#include <QCoreApplication>
#include <QMutex>
#include <QTime>
#include <QDebug>
#include <QMutexLocker>

#include "DataTypeDef.h"
#include "Globals.h"

AuthenticationHelper* authHelper = nullptr;
AuthenticationHelper *AuthenticationHelper::instance()
{
    static QMutex mutex;
    if (!authHelper) {
        QMutexLocker locker(&mutex);
        if (!authHelper) {
            authHelper = new AuthenticationHelper();
        }
    }

    return authHelper;
}

AuthenticationHelper::AuthenticationHelper(QObject *parent)
    : QObject{parent}
{}

bool AuthenticationHelper::getAuthResult(const QString &idTag)
{
    auto auth_list = GLOBALS->getValue(Global::Keys::AUTH_LIST).value<AUTH_LIST>();
    foreach (const auto &local_auth, std::as_const(auth_list.localAuthorizationList)) {
        if (local_auth.idTag == idTag) {
            // 后续添加判断逻辑
        }
    }

    foreach (const auto &auth_cache, std::as_const(auth_list.authorizationCache)) {
        if (auth_cache.idTag == idTag) {
            // 后续添加判断逻辑
        }
    }

    return false;
}
