using System.Security.Claims;

namespace Kbx.Shared.Runtime;

public static class RuntimeIdentity
{
    public static Guid TenantId(ClaimsPrincipal user) => Parse(user.FindFirst("tenant_id")?.Value ?? user.FindFirst("tenant")?.Value);
    public static Guid UserId(ClaimsPrincipal user) => Parse(user.FindFirst(ClaimTypes.NameIdentifier)?.Value);

    private static Guid Parse(string? value) => Guid.TryParse(value, out var id) ? id : Guid.Empty;
}
