using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;

namespace ZB.MOM.WW.Telemetry;

/// <summary>
/// Endpoint extension for mounting the Prometheus <c>/metrics</c> scrape endpoint.
/// </summary>
public static class ZbMetricsEndpointExtensions
{
    /// <summary>
    /// Mounts the Prometheus <c>/metrics</c> endpoint. Valid under <em>any</em>
    /// <see cref="ZbTelemetryOptions.Exporter"/> value: the Prometheus exporter is always wired by
    /// <c>AddZbTelemetry</c>, and OTLP (<see cref="ZbExporter.Otlp"/>) is only an additive overlay —
    /// so <c>/metrics</c> serves scrape data even when <c>Exporter = ZbExporter.Otlp</c>.
    /// Call after <c>app.UseRouting()</c>.
    /// </summary>
    /// <param name="endpoints">The endpoint route builder.</param>
    public static IEndpointConventionBuilder MapZbMetrics(this IEndpointRouteBuilder endpoints)
    {
        ArgumentNullException.ThrowIfNull(endpoints);
        return endpoints.MapPrometheusScrapingEndpoint();
    }
}
