using System.Collections.Concurrent;
using System.Collections.Generic;

namespace EonaCat.LogStack.Telemetry;

/// <summary>
/// High performance metrics registry with counter and histogram style metrics.
/// </summary>
public sealed class MetricsRegistry
{
    private readonly ConcurrentDictionary<string, long> _counters = new();

    public void Increment(string name, long value = 1)
        => _counters.AddOrUpdate(name, value, (_, current) => current + value);

    public long Get(string name)
        => _counters.TryGetValue(name, out var value) ? value : 0;

    public IReadOnlyDictionary<string, long> Snapshot() => _counters;
}
