using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
namespace EonaCat.LogStack.Telemetry;
public sealed class TelemetryClient : IDisposable
{
    private readonly HttpClient _http = new HttpClient();
    private readonly Uri _endpoint;
    public TelemetryClient(string endpoint) => _endpoint = new Uri(endpoint.TrimEnd('/') + "/telemetry");
    public Task TrackAsync(TelemetryEvent evt, CancellationToken token = default)
    {
        var json = JsonSerializer.Serialize(evt);
        return _http.PostAsync(_endpoint, new StringContent(json, Encoding.UTF8, "application/json"), token);
    }
    public void Dispose() => _http.Dispose();
}
