using MediatR;
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;
using System.Threading.Tasks;

namespace NetworkResurrector.Api.Application.Queries
{
    public class GetUserPermissions
    {
        public class Query : IRequest<Model> { }

        public class Model
        {
            public IEnumerable<string> Permissions { get; set; }
        }

        public class QueryHandler : IRequestHandler<Query, Model>
        {
            private readonly IUserContext _userContext;

            public QueryHandler(IUserContext userContext)
            {
                _userContext=userContext;
            }

            public async Task<Model> Handle(Query request, CancellationToken cancellationToken)
            {
                var permissions = await _userContext.GetUserPermissions();
                return new Model()
                {
                    Permissions = permissions
                };
            }
        }
    }
}
