using Microsoft.AspNetCore.Http;
using System.Security.Claims;
using XF.Domain.Dependency;

namespace DataSharing.Application.Identity
{
    public class DefaultSessionContext : ISharingSessionContext, IScopeDependency
    {
        public DefaultSessionContext(IHttpContextAccessor httpContextAccessor)
        {
            var httpContext = httpContextAccessor.HttpContext;
            if (httpContext is null)
                return;

            var user = httpContext.User;
            Id = user.FindFirstValue(ClaimTypes.NameIdentifier);
            AccountId = user.FindFirstValue(AppClaimTypes.AccountId);
            PlatformSource = user.FindFirstValue(AppClaimTypes.PlatformSource);
            PlatformSourceName = user.FindFirstValue(AppClaimTypes.PlatformSourceName);
        }

        public string? Id { get; set; }

        public string? AccountId { get; set; }

        public string? PlatformSource { get; set; }

        public string? PlatformSourceName { get; set; }
    }
}
