#include <docopt.h>
#include <future>
#include <health/outputs/AlarmsOutputs.h>
#include <sdbus-c++/sdbus-c++.h>
#include <spdlog/sinks/ansicolor_sink.h>
#include <spdlog/spdlog.h>
#include <sysrepo-cpp/Connection.hpp>
#include "VELIA_VERSION.h"
#include "health/Factory.h"
#include "health/alarms/SystemdUnits.h"
#include "health/outputs/callables.h"
#include "main.h"
#include "utils/exceptions.h"
#include "utils/journal.h"
#include "utils/log-init.h"
#include "utils/log.h"

static const char usage[] =
    R"(Monitor system health status.

Usage:
  veliad-health
    [--appliance=<Model>]
    [--health-log-level=<Level>]
  veliad-health (-h | --help)
  veliad-health --version

Options:
  -h --help                         Show this screen.
  --version                         Show version.
  --health-log-level=<N>            Log level for the health monitoring [default: 3]
                                    (0 -> critical, 1 -> error, 2 -> warning, 3 -> info,
                                    4 -> debug, 5 -> trace)
)";

DBUS_EVENTLOOP_INIT

int main(int argc, char* argv[])
{
    std::shared_ptr<spdlog::sinks::sink> loggingSink;
    if (velia::utils::isJournaldActive()) {
        loggingSink = velia::utils::create_journald_sink();
    } else {
        loggingSink = std::make_shared<spdlog::sinks::ansicolor_stderr_sink_mt>();
    }

    auto args = docopt::docopt(usage, {argv + 1, argv + argc}, true, "veliad-health " VELIA_VERSION, true);

    velia::utils::initLogs(loggingSink);
    spdlog::set_level(spdlog::level::info);

    try {
        spdlog::get("health")->set_level(parseLogLevel("Health checker logger", args["--health-log-level"]));

        DBUS_EVENTLOOP_START

        auto srSessionAlarms = sysrepo::Connection{}.sessionStart();
        srSessionAlarms.switchDatastore(sysrepo::Datastore::Operational);

        // output configuration
        std::vector<std::function<void(velia::health::State)>> outputHandlers;
        if (const auto& appliance = args["--appliance"]) {
            spdlog::get("health")->debug("Initializing LED drivers");
            outputHandlers.emplace_back(velia::health::createOutput(appliance.asString()));
        }
        velia::health::AlarmsOutputs alarms(srSessionAlarms, outputHandlers);

        spdlog::get("health")->debug("All outputs initialized.");

        // input configuration
        spdlog::get("health")->debug("Starting DBus systemd units watcher");
        auto srSessionSystemdUnits = sysrepo::Connection{}.sessionStart();
        auto inputSystemdDbus = std::make_shared<velia::health::SystemdUnits>(srSessionSystemdUnits, *g_dbusConnection);

        DBUS_EVENTLOOP_END;

        return 0;
    } catch (std::exception& e) {
        velia::utils::fatalException(spdlog::get("main"), e, "main");
    }
}
