#pragma once

#include <chrono>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

namespace net::eagle0::common {

using ShardokLatencyFields = std::vector<std::pair<std::string, std::string>>;

auto ShardokLatencyTraceEnabledForGame(std::string_view gameId) -> bool;

void EmitShardokLatencyTrace(
        std::string_view event,
        std::string_view gameId,
        const ShardokLatencyFields& fields,
        std::chrono::steady_clock::duration duration);

class ScopedShardokLatencyTrace {
public:
    ScopedShardokLatencyTrace(
            std::string event,
            std::string gameId,
            ShardokLatencyFields fields = {});
    ~ScopedShardokLatencyTrace();

    ScopedShardokLatencyTrace(const ScopedShardokLatencyTrace&) = delete;
    auto operator=(const ScopedShardokLatencyTrace&) -> ScopedShardokLatencyTrace& = delete;
    ScopedShardokLatencyTrace(ScopedShardokLatencyTrace&&) = delete;
    auto operator=(ScopedShardokLatencyTrace&&) -> ScopedShardokLatencyTrace& = delete;

private:
    std::string event_;
    std::string gameId_;
    ShardokLatencyFields fields_;
    std::optional<std::chrono::steady_clock::time_point> start_;
};

}  // namespace net::eagle0::common
