using System.Net.Http.Json; using System.Text.Json.Serialization; using Big.Application; namespace Big.Infrastructure; /// /// HTTP client to the ACL service — the boundary the domain crosses to open a zaak (§8.1). It POSTs /// the bsn to the ACL's /zaken endpoint and returns the created zaak URL; it never constructs /// ZGW URLs or talks to OpenZaak itself. /// public sealed class AclHttpClient(HttpClient http, AclOptions options) : IAclClient { public async Task OpenZaakAsync(string bsn, CancellationToken ct = default) { using var response = await http.PostAsJsonAsync( new Uri(options.BaseUrl, "zaken"), new OpenZaakRequest(bsn), ct); response.EnsureSuccessStatusCode(); var opened = await response.Content.ReadFromJsonAsync(ct) ?? throw new InvalidOperationException("The ACL returned an empty zaak response."); return new Uri(opened.ZaakUrl); } public async Task ApproveZaakAsync(Uri zaakUrl, CancellationToken ct = default) { ArgumentNullException.ThrowIfNull(zaakUrl); using var response = await http.PostAsJsonAsync( new Uri(options.BaseUrl, "statussen"), new SetStatusRequest(zaakUrl.ToString()), ct); response.EnsureSuccessStatusCode(); } private sealed record OpenZaakRequest([property: JsonPropertyName("bsn")] string Bsn); private sealed record OpenZaakResponse([property: JsonPropertyName("zaakUrl")] string ZaakUrl); private sealed record SetStatusRequest([property: JsonPropertyName("zaakUrl")] string ZaakUrl); }