// ***********************************************************************
// 
//    AgileWebs
// 
// ***********************************************************************
using Core.Thalos.Adapters;
using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Microsoft.AspNetCore.Http;
using MongoDB.Bson;
using System.Security.Claims;
namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers
{
    /// 
    /// Handles mappings between
    /// ,
    /// and 
    /// 
    public static class RoleMapper
    {
        /// 
        /// Maps the RoleRequest to RoleAdapter.
        /// 
        /// The Role to be mapped.
        /// A  representing
        /// the asynchronous execution of the service.
        public static RoleAdapter ToAdapter(this RoleRequest newRole, IHttpContextAccessor httpContextAccessor)
        {
            return new RoleAdapter
            {
                Id = ObjectId.GenerateNewId().ToString(),
                Name = newRole.Name,
                Description = newRole.Description,
                Applications = newRole.Applications,
                Modules = newRole.Modules,
                Permissions = newRole.Permissions,
                CreatedAt = DateTime.UtcNow,
                CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty
            };
        }
    }
}