#include "systemd_service_parser.hpp"
#include "systemd_target_parser.hpp"
#include "systemd_target_signal.hpp"

#include <CLI/CLI.hpp>
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>

#include <iostream>
#include <vector>

PHOSPHOR_LOG2_USING;

bool gVerbose = false;

void dump_targets(const TargetErrorData& targetData)
{
    std::cout << "## Data Structure of Json ##" << std::endl;
    for (const auto& [target, value] : targetData)
    {
        std::cout << target << " " << value.errorToLog << std::endl;
        std::cout << "    ";
        for (const auto& eToMonitor : value.errorsToMonitor)
        {
            std::cout << eToMonitor << ", ";
        }
        std::cout << std::endl;
    }
    std::cout << std::endl;
}

void print_usage(void)
{
    std::cout << "[-f <file1> -f <file2> ...] : Full path to json file(s) with "
                 "target/error mappings"
              << std::endl;
    std::cout << "[-s <file1> -s <file2> ...] : Full path to json file(s) with "
                 "services to monitor for errors"
              << std::endl;
    return;
}

int main(int argc, char* argv[])
{
    auto bus = sdbusplus::bus::new_default();
    std::vector<std::string> targetFilePaths;
    std::vector<std::string> serviceFilePaths;

    CLI::App app{"OpenBmc systemd target and service monitor"};
    app.add_option("-f,--file", targetFilePaths,
                   "Full path to json file(s) with target/error mappings");
    app.add_option("-s,--service", serviceFilePaths,
                   "Full path to json file(s) with services to monitor");
    app.add_flag("-v", gVerbose, "Enable verbose output");

    CLI11_PARSE(app, argc, argv);

    // target file input required
    if (targetFilePaths.empty())
    {
        error("No input files");
        print_usage();
        exit(-1);
    }

    TargetErrorData targetData = parseFiles(targetFilePaths);
    if (targetData.size() == 0)
    {
        error("Invalid input files, no targets found");
        print_usage();
        exit(-1);
    }

    ServiceMonitorData serviceData;
    if (!serviceFilePaths.empty())
    {
        serviceData = parseServiceFiles(serviceFilePaths);
    }

    if (gVerbose)
    {
        dump_targets(targetData);
    }

    phosphor::state::manager::SystemdTargetLogging targetMon(
        targetData, serviceData, bus);

    // Subscribe to systemd D-bus signals indicating target completions
    targetMon.subscribeToSystemdSignals();

    bus.process_loop();
    return 0;
}
