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);
}
private sealed record OpenZaakRequest([property: JsonPropertyName("bsn")] string Bsn);
private sealed record OpenZaakResponse([property: JsonPropertyName("zaakUrl")] string ZaakUrl);
}