#include "foundation/diagnostics/ActionOutcome.h"

#include <mutex>
#include <utility>

namespace
{
    std::mutex g_outcomes_mutex;
    std::vector<ta::foundation::action_outcomes::ActionOutcome> g_outcomes;
}

namespace ta::foundation::action_outcomes
{
    void publish(ActionOutcome outcome)
    {
        std::scoped_lock lock(g_outcomes_mutex);
        g_outcomes.push_back(std::move(outcome));
    }

    std::vector<ActionOutcome> drain()
    {
        std::scoped_lock lock(g_outcomes_mutex);
        std::vector<ActionOutcome> result;
        result.swap(g_outcomes);
        return result;
    }

    void clear() noexcept
    {
        std::scoped_lock lock(g_outcomes_mutex);
        g_outcomes.clear();
    }
}
