using System.Diagnostics;
using Nexus.Api.Observability;
using Xunit;

namespace Nexus.Api.Tests;

public sealed class NexusTelemetryTests
{
    [Fact]
    public void RedactionProcessor_RemovesContentBearingTagsAndKeepsSafeDimensions()
    {
        using var activity = new Activity("redaction-test");
        activity.SetTag("url.query", "token=secret");
        activity.SetTag("url.full", "https://nexus.test/tasks?token=secret");
        activity.SetTag("url.path", "/api/v1/openclaw/agents/private-agent/files/SOUL.md");
        activity.SetTag("http.url", "https://nexus.test/tasks?token=secret");
        activity.SetTag("http.target", "/tasks?token=secret");
        activity.SetTag("exception.message", "secret prompt");
        activity.SetTag("exception.stacktrace", "C:\\private\\workspace");
        activity.SetTag("db.statement", "select * from secret");
        activity.SetTag("db.query.text", "select * from secret");
        activity.SetTag("http.request.method", "GET");

        new NexusTelemetryRedactionProcessor().OnEnd(activity);

        Assert.Null(activity.GetTagItem("url.query"));
        Assert.Null(activity.GetTagItem("url.full"));
        Assert.Null(activity.GetTagItem("url.path"));
        Assert.Null(activity.GetTagItem("http.url"));
        Assert.Null(activity.GetTagItem("http.target"));
        Assert.Null(activity.GetTagItem("exception.message"));
        Assert.Null(activity.GetTagItem("exception.stacktrace"));
        Assert.Null(activity.GetTagItem("db.statement"));
        Assert.Null(activity.GetTagItem("db.query.text"));
        Assert.Equal("GET", activity.GetTagItem("http.request.method"));
    }

    [Fact]
    public void BrowserMetrics_UseSemanticUnits()
    {
        Assert.Equal("ms", NexusTelemetry.BrowserDuration.Unit);
        Assert.Equal("1", NexusTelemetry.BrowserScore.Unit);
    }
}
