/*
 * Copyright (C) 2024 CESNET, https://photonics.cesnet.cz/
 *
 * Written by Tomáš Pecka <tomas.pecka@cesnet.cz>
 *
 */

#include "alarms.h"

AlarmWatcher::AlarmWatcher(sysrepo::Session& session)
    : datastoreWatcher(session, "/ietf-alarms:alarms/alarm-inventory")
    , rpcWatcher(session, "/sysrepo-ietf-alarms:create-or-update-alarm")
{
}

void AlarmWatcher::AlarmInventory::add(const std::vector<std::string>& alarmTypeIds, const std::vector<std::string>& resources, const std::vector<std::string>& severities)
{
    for (const auto& type : alarmTypeIds) {
        auto& alarm = inventory[type];
        alarm.resources.insert(resources.begin(), resources.end());
        alarm.severities.insert(severities.begin(), severities.end());
    }
}

bool AlarmWatcher::AlarmInventory::contains(const std::string& alarmTypeId, const std::optional<std::string>& resource, const std::optional<std::string>& severity) const
{
    if (auto it = inventory.find(alarmTypeId); it != inventory.end()) {
        const auto& alarm = it->second;

        if (resource && !alarm.resources.empty() && !alarm.resources.contains(*resource)) {
            return false;
        }

        if (severity && *severity != "cleared" && !alarm.severities.empty() && !alarm.severities.contains(*severity)) {
            return false;
        }
    }
    return true;
}
