using DocumentFormat.OpenXml.Office2013.Excel;
using Hotline.Application.Exam.Core.Extensions;
using Hotline.Application.Exam.Extensions;
using Hotline.Share.Enums.Exams;
using Hotline.Share.Requests.Exam;
using Hotline.Share.Requests.TestPaper;
using JiebaNet.Segmenter.Common;
using System.Linq.Expressions;
using Hotline.Application.Exam.Core.Utilities;
using Hotline.Exams.Practices;
using Hotline.Exams.Questions;

namespace Hotline.Application.Exam.QueryExtensions.Practices
{
    public static class PracticeQueryExtensions
    {
        public static Expression<Func<ExamPractice,bool>> GetExpression(this PracticePagedRequest practicePagedRequest)
        {
            Expression<Func<ExamPractice, bool>> expression = m => m.Id != null;

            expression = ExpressionableUtility.CreateExpression<ExamPractice>()
                .ToExpression();

            return expression;
        }

        public static Expression<Func<ExamPracticeQuestion,bool>> GetExpression(this PracticeQuestionGroupRequest practiceQuestionGroupRequest)
        {
            Expression<Func<ExamPracticeQuestion, bool>> expression = m => m.Id != null;

            expression = ExpressionableUtility.CreateExpression<ExamPracticeQuestion>()
                .AndIF(practiceQuestionGroupRequest.PracticeId.IsNotNull(),x=>x.PracticeId == practiceQuestionGroupRequest.PracticeId)
                .And(x=>x.QuestionType == EQuestionType.Single || x.QuestionType == EQuestionType.Multi || x.QuestionType == EQuestionType.Judge)
                .ToExpression();

            return expression;
        }

        public static Expression<Func<ExamPracticeQuestion,bool>> GetExpression(this PracticeQuestionRequest practiceQuestionRequest)
        {
            Expression<Func<ExamPracticeQuestion, bool>> expression = m => m.Id != null;

            expression = ExpressionableUtility.CreateExpression<ExamPracticeQuestion>()
                .AndIF(practiceQuestionRequest.PracticeQuestionId.IsNotNull(), x => x.Id == practiceQuestionRequest.PracticeQuestionId)
                .ToExpression();

            return expression;
        }

        public static Expression<Func<ExamQuestionTag, bool>> GetExpression(this TagQuestionCountForPracticeRequest tagQuestionCountForPracticeRequest)
        {
            Expression<Func<ExamQuestionTag, bool>> expression = m => m.Id != null;

            expression = ExpressionableUtility.CreateExpression<ExamQuestionTag>()
               .AndIF(tagQuestionCountForPracticeRequest.TagIds.IsNotNullOrEmpty() && tagQuestionCountForPracticeRequest.TagIds.Any(), x => tagQuestionCountForPracticeRequest.TagIds.Contains(x.TagId))               
               .ToExpression();

            return expression;
        }

        public static Expression<Func<ExamQuestion, bool>> GetQuestionExpression(this TagQuestionCountForPracticeRequest tagQuestionCountForPracticeRequest)
        {
            Expression<Func<ExamQuestion, bool>> expression = m => m.Id != null;
            expression = ExpressionableUtility.CreateExpression<ExamQuestion>()
            .And(x=>x.QuestionType == EQuestionType.Single || x.QuestionType == EQuestionType.Multi || x.QuestionType == EQuestionType.Judge)
            .ToExpression();

            return expression;
        }
    }
}
