using System.Net.Http.Headers;

namespace JSMR.UI.Blazor.Services;

public sealed class JwtAuthorizationMessageHandler(TokenStore tokens) : DelegatingHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ct)
    {
        if (!string.IsNullOrWhiteSpace(tokens.AccessToken))
        {
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);
        }

        return base.SendAsync(request, ct);
    }
}

public sealed class TokenStore
{
    public string? AccessToken { get; set; }
}