using Microsoft.AspNetCore.Components.Authorization;

namespace StandManager.Utils;

public static class MembershipUtils
{
    public static async Task<Guid> GetUserId(AuthenticationStateProvider auth)
    {
        var state = await auth.GetAuthenticationStateAsync();
        var idClaim = state.User.FindFirst("UserId")?.Value;

        return Guid.Parse(idClaim ?? Guid.Empty.ToString());
    }
    
    public static async Task<Guid> GetRoleId(AuthenticationStateProvider auth)
    {
        var state = await auth.GetAuthenticationStateAsync();
        var idClaim = state.User.FindFirst("RoleId")?.Value;

        return Guid.Parse(idClaim ?? Guid.Empty.ToString());
    }
}
