using Netmash.Security.Authentication.Tuitio.Abstractions;
using NetworkResurrector.Api.Application.Services.Abstractions;
using NetworkResurrector.Api.Domain.Repositories;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NetworkResurrector.Api.Application.Services
{
    internal class UserContext : IUserContext
    {
        private readonly IUserContextAccessor _userContext;
        private readonly ISecurityRepository _securityRepository;

        public UserContext(IUserContextAccessor userContext, ISecurityRepository securityRepository)
        {
            _userContext=userContext;
            _securityRepository=securityRepository;
        }

        public async Task<IEnumerable<string>> GetUserPermissions()
        {
            var roles = _userContext.UserRoles.Select(r => r.id);
            var permissions = await _securityRepository.GetUserPermissionCodes(roles);
            return permissions;
        }
    }
}
