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

namespace YGNT.QuestionLibrary.EntityFrameworkCore.Repositories
{
    public class TextbookRepository : QuestionLibraryRepositoryBase<Textbook>, ITextbookRepository
    {
        private readonly IDisciplineFilter _disciplineFilter;

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

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