using Exam.Infrastructure.Extensions;
using Hotline.Application.Exam.Extensions;
using Hotline.Share.Requests.Question;
using JiebaNet.Segmenter.Common;
using SqlSugar;
using System.Linq.Expressions;
using Hotline.Application.Exam.Core.Utilities;
using Hotline.Exams.ExamManages;
using Hotline.Exams.Questions;
using ExamQuestion = Hotline.Exams.Questions.ExamQuestion;
using ExamQuestionKnowladge = Hotline.Exams.Questions.ExamQuestionKnowladge;

namespace Hotline.Application.Exam.QueryExtensions.Questions
{
    public static class QuestionQueryExtesions
    {
        public static Expression<Func<ExamQuestion, bool>> GetExpression(this QuestionPagedRequest questionPagedRequest)
        {
            Expression<Func<ExamQuestion, bool>> expression = m => m.Id != null;

            expression = ExpressionableUtility.CreateExpression<ExamQuestion>().AndIF(questionPagedRequest.DifficultyLevel.IsNotNull(), x => questionPagedRequest.DifficultyLevel == x.DifficultyLevel)
            .AndIF(questionPagedRequest.Title.IsNotNullOrEmpty(), x => x.Title.Contains(questionPagedRequest.Title))
           .AndIF(questionPagedRequest.QuestionType.IsNotNull(),x=>x.QuestionType == questionPagedRequest.QuestionType)
            .ToExpression();
            return expression;
        }

        public static Expression<Func<ExamQuestionTag, bool>> GetQuestionTagExpression(this QuestionPagedRequest questionPagedRequest)
        {
            Expression<Func<ExamQuestionTag, bool>> expression = m => m.Id != null;

            expression = ExpressionableUtility.CreateExpression<ExamQuestionTag>().AndIF(questionPagedRequest.TagIds.IsNotNullOrEmpty(), x => questionPagedRequest.TagIds.Contains(x.TagId))
            .ToExpression();
            return expression;
        }

        public static Expression<Func<ExamTag, bool>> GetExamTagExpression(this QuestionPagedRequest questionPagedRequest)
        {
            Expression<Func<ExamTag, bool>> expression = m => m.Id != null;

            expression = ExpressionableUtility.CreateExpression<ExamTag>().
            AndIF(questionPagedRequest.TagIds.IsNotNullOrEmpty(), x => questionPagedRequest.TagIds.Contains(x.Id))
            .ToExpression();

            return expression;
        }

        public static Expression<Func<ExamQuestionKnowladge, bool>> GetQuestionKnowladgeExpression(this QuestionPagedRequest questionPagedRequest)
        {
            Expression<Func<ExamQuestionKnowladge, bool>> expression = m => m.Id != null;

            expression = ExpressionableUtility.CreateExpression<ExamQuestionKnowladge>().
            AndIF(questionPagedRequest.KnowladgeIds.IsNotNullOrEmpty(), x => questionPagedRequest.KnowladgeIds.Contains(x.KnowladgeId))
            .ToExpression();

            return expression;
        }
    }
}
