#include "config.h"

#include "manager.hpp"

#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/exception.hpp>
#include <xyz/openbmc_project/Led/Physical/server.hpp>

#include <algorithm>
#include <iostream>
#include <string>
namespace phosphor
{
namespace led
{

// apply the led action to the map
static void applyGroupAction(std::map<LedName, Layout::LedAction>& newState,
                             Layout::LedAction action)
{
    if (!newState.contains(action.name))
    {
        newState[action.name] = action;
        return;
    }

    auto currentAction = newState[action.name];

    const bool hasPriority = currentAction.priority.has_value();

    if (hasPriority && currentAction.action == action.priority)
    {
        // if the current action is already the priority action,
        // we cannot override it
        return;
    }

    newState[action.name] = action;
}

// create the resulting new map from all currently asserted groups
static auto getNewMapWithGroupPriorities(
    std::set<const Layout::GroupLayout*, Layout::CompareGroupLayout> sorted)
    -> std::map<LedName, Layout::LedAction>
{
    std::map<LedName, Layout::LedAction> newState;

    // update the new map with the desired state
    for (const auto* it : sorted)
    {
        // apply all led actions of that group to the map
        for (const Layout::LedAction& action : it->actionSet)
        {
            newState[action.name] = action;
        }
    }
    return newState;
}

static std::map<LedName, Layout::LedAction> getNewMapWithLEDPriorities(
    std::set<const Layout::GroupLayout*> assertedGroups)
{
    std::map<LedName, Layout::LedAction> newState;
    // update the new map with the desired state
    for (const Layout::GroupLayout* it : assertedGroups)
    {
        // apply all led actions of that group to the map
        for (const Layout::LedAction& action : it->actionSet)
        {
            applyGroupAction(newState, action);
        }
    }
    return newState;
}

// create the resulting new map from all currently asserted groups
std::map<LedName, Layout::LedAction>
    Manager::getNewMap(std::set<const Layout::GroupLayout*> assertedGroups)
{
    std::map<LedName, Layout::LedAction> newState;

    std::set<const Layout::GroupLayout*, Layout::CompareGroupLayout> sorted;

    bool groupPriorities = false;

    for (const Layout::GroupLayout* it : assertedGroups)
    {
        sorted.insert(it);

        if (it->priority != 0)
        {
            groupPriorities = true;
        }
    }

    if (groupPriorities)
    {
        newState = getNewMapWithGroupPriorities(sorted);
    }
    else
    {
        newState = getNewMapWithLEDPriorities(assertedGroups);
    }

    return newState;
}

// Assert -or- De-assert
bool Manager::setGroupState(const std::string& path, bool assert,
                            ActionSet& ledsAssert, ActionSet& ledsDeAssert)
{
    if (assert)
    {
        assertedGroups.insert(&ledMap.at(path));
    }
    else
    {
        if (assertedGroups.contains(&ledMap.at(path)))
        {
            assertedGroups.erase(&ledMap.at(path));
        }
    }

    // create the new map from the asserted groups
    auto newState = getNewMap(assertedGroups);

    // the ledsAssert are those that are in the new map and change state
    // + those in the new map and not in the old map
    for (const auto& [name, action] : newState)
    {
        if (ledStateMap.contains(name))
        {
            // check if the led action has changed
            auto& currentAction = ledStateMap[name];

            if (currentAction.action == action.action)
                continue;
        }

        ledsAssert.insert(action);
    }

    // the ledsDeAssert are those in the old map but not in the new map
    for (const auto& [name, action] : ledStateMap)
    {
        if (!newState.contains(name))
        {
            ledsDeAssert.insert(action);
        }
    }

    ledStateMap = newState;

    // If we survive, then set the state accordingly.
    return assert;
}

void Manager::setLampTestCallBack(
    std::function<bool(ActionSet& ledsAssert, ActionSet& ledsDeAssert)>
        callBack)
{
    lampTestCallBack = callBack;
}

/** @brief Run through the map and apply action on the LEDs */
void Manager::driveLEDs(ActionSet& ledsAssert, ActionSet& ledsDeAssert)
{
#ifdef USE_LAMP_TEST
    // Use the lampTestCallBack method and trigger the callback method in the
    // lamp test(processLEDUpdates), in this way, all lamp test operations
    // are performed in the lamp test class.
    if (lampTestCallBack(ledsAssert, ledsDeAssert))
    {
        return;
    }
#endif
    ActionSet newReqChangedLeds;
    std::vector<std::pair<ActionSet&, ActionSet&>> actionsVec = {
        {reqLedsAssert, ledsAssert}, {reqLedsDeAssert, ledsDeAssert}};

    timer.setEnabled(false);
    std::set_union(ledsAssert.begin(), ledsAssert.end(), ledsDeAssert.begin(),
                   ledsDeAssert.end(),
                   std::inserter(newReqChangedLeds, newReqChangedLeds.begin()),
                   ledLess);

    // prepare reqLedsAssert & reqLedsDeAssert
    for (auto pair : actionsVec)
    {
        ActionSet tmpSet;

        // Discard current required LED actions, if these LEDs have new actions
        // in newReqChangedLeds.
        std::set_difference(pair.first.begin(), pair.first.end(),
                            newReqChangedLeds.begin(), newReqChangedLeds.end(),
                            std::inserter(tmpSet, tmpSet.begin()), ledLess);

        // Union the remaining LED actions with new LED actions.
        pair.first.clear();
        std::set_union(tmpSet.begin(), tmpSet.end(), pair.second.begin(),
                       pair.second.end(),
                       std::inserter(pair.first, pair.first.begin()), ledLess);
    }

    driveLedsHandler();
    return;
}

// Calls into driving physical LED post choosing the action
int Manager::drivePhysicalLED(const std::string& objPath, Layout::Action action,
                              uint8_t dutyOn, uint16_t period)
{
    try
    {
        // If Blink, set its property
        if (action == Layout::Action::Blink)
        {
            PropertyValue dutyOnValue{dutyOn};
            PropertyValue periodValue{period};

            phosphor::led::utils::DBusHandler::setProperty(
                objPath, phyLedIntf, "DutyOn", dutyOnValue);
            phosphor::led::utils::DBusHandler::setProperty(
                objPath, phyLedIntf, "Period", periodValue);
        }

        PropertyValue actionValue{getPhysicalAction(action)};
        phosphor::led::utils::DBusHandler::setProperty(objPath, phyLedIntf,
                                                       "State", actionValue);
    }
    catch (const sdbusplus::exception_t& e)
    {
        lg2::error(
            "Error setting property for physical LED, ERROR = {ERROR}, OBJECT_PATH = {PATH}",
            "ERROR", e, "PATH", objPath);
        return -1;
    }

    return 0;
}

/** @brief Returns action string based on enum */
std::string Manager::getPhysicalAction(Layout::Action action)
{
    namespace server = sdbusplus::xyz::openbmc_project::Led::server;

    // TODO: openbmc/phosphor-led-manager#5
    //    Somehow need to use the generated Action enum than giving one
    //    in ledlayout.
    if (action == Layout::Action::On)
    {
        return server::convertForMessage(server::Physical::Action::On);
    }
    else if (action == Layout::Action::Blink)
    {
        return server::convertForMessage(server::Physical::Action::Blink);
    }
    else
    {
        return server::convertForMessage(server::Physical::Action::Off);
    }
}

void Manager::driveLedsHandler(void)
{
    ActionSet failedLedsAssert;
    ActionSet failedLedsDeAssert;

    // This order of LED operation is important.
    for (const auto& it : reqLedsDeAssert)
    {
        std::string objPath = std::string(phyLedPath) + it.name;
        lg2::debug("De-Asserting LED, NAME = {NAME}, ACTION = {ACTION}", "NAME",
                   it.name, "ACTION", it.action);
        if (drivePhysicalLED(objPath, Layout::Action::Off, it.dutyOn,
                             it.period) != 0)
        {
            failedLedsDeAssert.insert(it);
        }
    }

    for (const auto& it : reqLedsAssert)
    {
        std::string objPath = std::string(phyLedPath) + it.name;
        lg2::debug("Asserting LED, NAME = {NAME}, ACTION = {ACTION}", "NAME",
                   it.name, "ACTION", it.action);
        if (drivePhysicalLED(objPath, it.action, it.dutyOn, it.period) != 0)
        {
            failedLedsAssert.insert(it);
        }
    }

    reqLedsAssert = failedLedsAssert;
    reqLedsDeAssert = failedLedsDeAssert;

    if (reqLedsDeAssert.empty() && reqLedsAssert.empty())
    {
        timer.setEnabled(false);
    }
    else
    {
        timer.restartOnce(std::chrono::seconds(1));
    }

    return;
}

} // namespace led
} // namespace phosphor
