using System.Threading;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Tokens;

namespace StellaOps.Auth.Client;

/// <summary>
/// Abstraction for requesting tokens from StellaOps Authority.
/// </summary>
public interface IStellaOpsTokenClient
{
    /// <summary>
    /// Requests an access token using the resource owner password credentials flow.
    /// </summary>
    Task<StellaOpsTokenResult> RequestPasswordTokenAsync(string username, string password, string? scope = null, CancellationToken cancellationToken = default);

    /// <summary>
    /// Requests an access token using the client credentials flow.
    /// </summary>
    Task<StellaOpsTokenResult> RequestClientCredentialsTokenAsync(string? scope = null, CancellationToken cancellationToken = default);

    /// <summary>
    /// Retrieves the cached JWKS document.
    /// </summary>
    Task<JsonWebKeySet> GetJsonWebKeySetAsync(CancellationToken cancellationToken = default);

    /// <summary>
    /// Retrieves a cached token entry.
    /// </summary>
    ValueTask<StellaOpsTokenCacheEntry?> GetCachedTokenAsync(string key, CancellationToken cancellationToken = default);

    /// <summary>
    /// Persists a token entry in the cache.
    /// </summary>
    ValueTask CacheTokenAsync(string key, StellaOpsTokenCacheEntry entry, CancellationToken cancellationToken = default);

    /// <summary>
    /// Removes a cached entry.
    /// </summary>
    ValueTask ClearCachedTokenAsync(string key, CancellationToken cancellationToken = default);
}
