using skydiveLogs_api.Domain;
using skydiveLogs_api.DomainBusiness.Interfaces;
using System;
using System.Linq;
using System.Security.Claims;

namespace skydiveLogs_api.DomainBusiness
{
    public class IdentityService : IIdentityService
    {
        #region Public Constructors

        public IdentityService(ClaimsPrincipal user)
        {
            if (user != null
                && user.Claims.Any())
            {
                var claims = user.Claims;

                ConnectedUser = new User();
                ConnectedUser.Login = claims.Single(c => c.Type == ClaimTypes.Name).Value;
                ConnectedUser.Id = Convert.ToInt32(claims.Single(c => c.Type == ClaimTypes.UserData).Value);
            }
        }

        #endregion Public Constructors

        #region Public Properties

        public User ConnectedUser { get; init; }

        #endregion Public Properties
    }
}