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

namespace YGNT.QuestionLibrary.EntityFrameworkCore.Repositories
{
    public class ChapterRepository :
        QuestionLibraryRepositoryBase<Chapter, long>,
        IChapterRepository
    {
        private readonly IDisciplineFilter _disciplineFilter;
        public ChapterRepository(IDbContextProvider<QuestionLibraryDbContext> dbContextProvider, IDisciplineFilter disciplineFilter) : base(dbContextProvider)
        {
            _disciplineFilter = disciplineFilter;
        }

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