using System.Linq;
using Abp.EntityFrameworkCore;
using YGNT.QuestionLibrary.Core.Disciplines;
using YGNT.QuestionLibrary.Core.IRepositories;
using YGNT.QuestionLibrary.EntityFrameworkCore.Repositories.Filter;

namespace YGNT.QuestionLibrary.EntityFrameworkCore.Repositories
{
    public class DisciplineQuestionTypeRepository :
        QuestionLibraryRepositoryBase<DisciplineQuestionType>, IDisciplineQuestionTypeRepository
    {
        private readonly IDisciplineFilter _disciplineFilter;

        public DisciplineQuestionTypeRepository(IDbContextProvider<QuestionLibraryDbContext> dbContextProvider, IDisciplineFilter disciplineFilter) : base(dbContextProvider)
        {
            _disciplineFilter = disciplineFilter;
        }

        protected override IQueryable<DisciplineQuestionType> GetQueryable()
        {
            return base.GetQueryable()
                .Where(x => _disciplineFilter.GetFilterQueryable()
                    .Select(f => f.Id).Contains(x.DisciplineId));
        }
    }
}