using System;
using System.Diagnostics.Metrics;

namespace StellaOps.Feedser.Source.Vndr.Adobe;

public sealed class AdobeDiagnostics : IDisposable
{
    public const string MeterName = "StellaOps.Feedser.Source.Vndr.Adobe";
    private static readonly string MeterVersion = "1.0.0";

    private readonly Meter _meter;
    private readonly Counter<long> _fetchAttempts;
    private readonly Counter<long> _fetchDocuments;
    private readonly Counter<long> _fetchFailures;
    private readonly Counter<long> _fetchUnchanged;

    public AdobeDiagnostics()
    {
        _meter = new Meter(MeterName, MeterVersion);
        _fetchAttempts = _meter.CreateCounter<long>(
            name: "adobe.fetch.attempts",
            unit: "operations",
            description: "Number of Adobe index fetch operations.");
        _fetchDocuments = _meter.CreateCounter<long>(
            name: "adobe.fetch.documents",
            unit: "documents",
            description: "Number of Adobe advisory documents captured.");
        _fetchFailures = _meter.CreateCounter<long>(
            name: "adobe.fetch.failures",
            unit: "operations",
            description: "Number of Adobe fetch failures.");
        _fetchUnchanged = _meter.CreateCounter<long>(
            name: "adobe.fetch.unchanged",
            unit: "documents",
            description: "Number of Adobe advisories skipped due to unchanged content.");
    }

    public Meter Meter => _meter;

    public void FetchAttempt() => _fetchAttempts.Add(1);

    public void FetchDocument() => _fetchDocuments.Add(1);

    public void FetchFailure() => _fetchFailures.Add(1);

    public void FetchUnchanged() => _fetchUnchanged.Add(1);

    public void Dispose() => _meter.Dispose();
}
