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 ?? []; } public async Task RejectAsync(string envelopeKey, string? reason, CancellationToken cancel = default) { using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server"); var response = await http.PostAsJsonAsync( $"/api/Annotation/reject/{Uri.EscapeDataString(envelopeKey)}", reason, _jsonOptions, cancel); if (!response.IsSuccessStatusCode) { var body = await response.Content.ReadAsStringAsync(cancel); throw new HttpRequestException( $"Failed to reject envelope {envelopeKey}: {(int)response.StatusCode} {response.StatusCode} - {body}", null, response.StatusCode); } } }