/*
 * Copyright 2023 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#include "resourcewarninghandler.h"

#include <QDebug>
#include <QString>

ResourceWarningHandler::ResourceWarningHandler(std::shared_ptr<ConfigManager> configManager,
                                               std::shared_ptr<SystemNotifiesSender> notifySender)
    : m_configManager(configManager)
    , m_notifySender(notifySender)
{
}

void ResourceWarningHandler::handleResourceWarning(const std::string &resource, int level)
{
    Q_UNUSED(level);
    Q_UNUSED(resource);

    if (!m_configManager->reousrceLimitEnabled()) {
        m_notifySender->sendResourceWarningNotify();
    } else if ("Memory" == resource && m_memoryWarningCallback) {
        m_memoryWarningCallback(level);
    }
}

void ResourceWarningHandler::setMemoryWarningHanlder(MemoryWarningCallback callback)
{
    m_memoryWarningCallback = std::move(callback);
}
