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

namespace YGNT.QuestionLibrary.EntityFrameworkCore.Repositories
{
    public class KnowledgePointRepository : QuestionLibraryRepositoryBase<KnowledgePoint, long>, IKnowledgePointRepository
    {
        private readonly IDisciplineFilter _disciplineFilter;


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

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