using System.Net; using System.Net.Http; using Microsoft.Extensions.Options; using EnvelopeGenerator.ReceiverUI.Options; namespace EnvelopeGenerator.ReceiverUI.Services; public class DocumentService(HttpClient http, IOptions apiOptions) { private readonly ApiOptions _api = apiOptions.Value; /// /// Fetches the PDF bytes for the given envelope key from the API. /// Returns null bytes with the HTTP status code on failure. /// public async Task<(byte[]? Bytes, HttpStatusCode StatusCode)> GetDocumentAsync(string envelopeKey, CancellationToken cancel = default) { var response = await http.GetAsync($"{_api.BaseUrl}/api/Document/{Uri.EscapeDataString(envelopeKey)}", cancel); if (!response.IsSuccessStatusCode) return (null, response.StatusCode); var bytes = await response.Content.ReadAsByteArrayAsync(cancel); return (bytes, response.StatusCode); } }