using System.Diagnostics;
using System.Diagnostics.Metrics;

namespace Nexus.Api.Observability;

/// <summary>
/// Low-cardinality diagnostics for the Nexus control plane. Content, prompts,
/// tool arguments, entity names, credentials and caller-provided identifiers
/// must never be recorded here.
/// </summary>
public static class NexusTelemetry
{
    public const string SourceName = "Nexus.Api";
    public static readonly ActivitySource ActivitySource = new(SourceName);
    public static readonly Meter Meter = new(SourceName);

    public static readonly Histogram<double> BrowserDuration =
        Meter.CreateHistogram<double>("nexus.browser.duration", unit: "ms");
    public static readonly Histogram<double> BrowserScore =
        Meter.CreateHistogram<double>("nexus.browser.score", unit: "1");
    public static readonly Histogram<double> TaskBoardDuration =
        Meter.CreateHistogram<double>("nexus.task.board.duration", unit: "ms");
    public static readonly Histogram<long> TaskBoardPayload =
        Meter.CreateHistogram<long>("nexus.task.board.payload", unit: "By");
    public static readonly Counter<long> SseResyncs =
        Meter.CreateCounter<long>("nexus.sse.resyncs");
    public static readonly UpDownCounter<long> SseSubscribers =
        Meter.CreateUpDownCounter<long>("nexus.sse.subscribers");
    public static readonly Histogram<double> GatewayRpcDuration =
        Meter.CreateHistogram<double>("nexus.gateway.rpc.duration", unit: "ms");
    public static readonly UpDownCounter<long> OutboxBacklog =
        Meter.CreateUpDownCounter<long>("nexus.outbox.backlog");
    public static readonly Counter<long> OutboxPublished =
        Meter.CreateCounter<long>("nexus.outbox.published");
    public static readonly Histogram<double> AgentProvisionDuration =
        Meter.CreateHistogram<double>("nexus.agent.provision.duration", unit: "ms");
}
