using LSFE.Infrastructure.Dto.Account;
using System.Security.Claims;

namespace LSFE.API.Helper
{
    public static class ClaimsPrincipalExtensions
    {
        public static UserClaimsDto? ToUserClaims(this ClaimsPrincipal user)
        {
            if (user?.Identity?.IsAuthenticated != true)
                return null;

            return new UserClaimsDto
            {
                UserId = user.FindFirstValue(ClaimTypes.NameIdentifier) ?? "",
                UserName = user.FindFirstValue(ClaimTypes.Name) ?? "",
                FullName = user.FindFirstValue("fullName") ?? "",
                Company = user.FindFirstValue("company") ?? "",
                Roles = user.FindAll(ClaimTypes.Role)
                            .Select(r => r.Value)
                            .ToList()
            };
        }
    }
}
