namespace NATS.Server.Subscriptions;

public sealed class SubListStats
{
    public uint NumSubs { get; set; }
    public uint NumCache { get; set; }
    public ulong NumInserts { get; set; }
    public ulong NumRemoves { get; set; }
    public ulong NumMatches { get; set; }
    public double CacheHitRate { get; set; }
    public uint MaxFanout { get; set; }
    public double AvgFanout { get; set; }

    internal int TotalFanout { get; set; }
    internal int CacheEntries { get; set; }
    internal ulong CacheHits { get; set; }

    public void Add(SubListStats stat)
    {
        NumSubs += stat.NumSubs;
        NumCache += stat.NumCache;
        NumInserts += stat.NumInserts;
        NumRemoves += stat.NumRemoves;
        NumMatches += stat.NumMatches;
        CacheHits += stat.CacheHits;
        if (MaxFanout < stat.MaxFanout)
            MaxFanout = stat.MaxFanout;

        TotalFanout += stat.TotalFanout;
        CacheEntries += stat.CacheEntries;
        if (TotalFanout > 0 && CacheEntries > 0)
            AvgFanout = (double)TotalFanout / CacheEntries;

        if (NumMatches > 0)
            CacheHitRate = (double)CacheHits / NumMatches;
    }
}
