using System.Linq;
using Abp.Domain.Repositories;
using Abp.Runtime.Session;
using YGNT.Infrastructure.Agent;
using YGNT.QuestionLibrary.Core.Disciplines;
using YGNT.QuestionLibrary.EntityFrameworkCore.Repositories.Filter;

namespace YGNT.QuestionLibrary.EntityFrameworkCore.Repositories
{
    public class DisciplineFilter : IDisciplineFilter
    {
        public DisciplineFilter(IRepository<Discipline> repository, IUserAgent userAgent)
        {
            _repository = repository;
            _userAgent = userAgent;
            AbpSession = NullAbpSession.Instance;
        }

        public IAbpSession AbpSession { get; set; }
        private readonly IRepository<Discipline> _repository;
        private readonly IUserAgent _userAgent;


        public IQueryable<Discipline> GetFilterQueryable()
        {
            var userId = AbpSession.UserId;
            var queryable = _repository.GetAll();
            if (userId.HasValue)
            {
                //if (!_userAgent.CheckUserIsAdmin(userId))
                //    queryable = queryable.Where(x => x.UserDisciplines.Any(f => f.UserId == userId));
            }
            return queryable;
        }
    }
}