namespace PlanTempus.Core.SeqLogging
{
    public class SeqHttpClient
    {
        HttpClient _httpClient;

        public SeqHttpClient(SeqConfiguration seqConfiguration, HttpMessageHandler httpMessageHandler)
        {
            _httpClient = new HttpClient(httpMessageHandler)
            {
                BaseAddress = new Uri(seqConfiguration.IngestionEndpoint),
                Timeout = TimeSpan.FromSeconds(30)
            };

            _httpClient.DefaultRequestHeaders.Accept.Clear();
            _httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            if (seqConfiguration.ApiKey != null)
                _httpClient.DefaultRequestHeaders.Add("X-Seq-ApiKey", seqConfiguration.ApiKey);
        }

        public SeqHttpClient(SeqConfiguration seqConfiguration) : this(seqConfiguration, new HttpClientHandler()) { }

        public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage httpRequestMessage, CancellationToken cancellationToken)
        {
            return await _httpClient.SendAsync(httpRequestMessage, cancellationToken);
        }
    }
}