using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using EnvelopeGenerator.Server.Client.Models;
namespace EnvelopeGenerator.Server.Client.Services;
///
/// Retrieves annotation positions from the API.
/// Uses relative paths (/api/Annotation/{envelopeKey}).
///
[Obsolete("Use SignatureService.")]
public class AnnotationService(IHttpClientFactory httpClientFactory)
{
private static readonly JsonSerializerOptions _jsonOptions = new(JsonSerializerDefaults.Web);
public async Task> GetAnnotationsAsync(string envelopeKey, CancellationToken cancel = default)
{
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
var url = $"/api/Annotation/{Uri.EscapeDataString(envelopeKey)}";
var response = await http.GetAsync(url, cancel);
if (!response.IsSuccessStatusCode)
return [];
var result = await response.Content.ReadFromJsonAsync>(_jsonOptions, cancel);
return result ?? [];
}
}