using FastEndpoints;
using KArtSell.BuildingBlocks.Time;
using KArtSell.Modules.ModelOperations.Observability;

namespace KArtSell.Modules.ModelOperations.Features.GetObservabilityMetrics;

public sealed class Endpoint(IObservabilityService observability, IClock clock) : EndpointWithoutRequest<Response>
{
    public override void Configure()
    {
        Get("/api/v1/observability/metrics");
        Roles("Auditor", "System", "Risk");
        Tags("Observability");
    }

    public override async Task HandleAsync(CancellationToken ct)
    {
        var metrics = await observability.GetMetricsAsync(ct);

        var response = new Response(
            metrics.BatchSla ?? new(),
            metrics.DataQuality ?? new(),
            metrics.DuplicateDetection ?? new(),
            metrics.Reconciliation ?? new(),
            metrics.ModelDrift ?? new(),
            clock.UtcNow.DateTime);

        await Send.OkAsync(response, ct);
    }
}
