#pragma once

#include <mutex>
#include <string>
#include <unordered_map>

#include "foundation/diagnostics/Logger.h"
#include "foundation/diagnostics/OnceLogger.h"

namespace ta::adapters::eft::aimbot::diag
{
    inline std::mutex counter_mutex;
    inline std::unordered_map<std::string, unsigned long long> counters;

    inline void info_once(const std::string& key, const std::string& message)
    {
        ta::foundation::diagnostics::OnceLogger::info("AIMBOT", key, message);
    }

    inline void warn_once(const std::string& key, const std::string& message)
    {
        ta::foundation::diagnostics::OnceLogger::warn("AIMBOT", key, message);
    }

    inline void error_once(const std::string& key, const std::string& message)
    {
        ta::foundation::diagnostics::OnceLogger::error("AIMBOT", key, message);
    }

    inline void info_every(const std::string& key,
                           const unsigned long long interval,
                           const std::string& message)
    {
        std::lock_guard lock(counter_mutex);
        const unsigned long long count = ++counters[key];
        if (interval == 0 || count == 1 || count % interval == 0)
            ta::foundation::logger::info("AIMBOT", message);
    }
}
