using Exam.Infrastructure.Extensions;
using Hotline.Share.Requests.Exam;
using JiebaNet.Segmenter.Common;
using System.Linq.Expressions;
using Hotline.Application.Exam.Core.Utilities;
using Hotline.Exams.ExamManages;

namespace Hotline.Application.Exam.QueryExtensions.ExamManages
{
    public static class ExamManageQueryExtensions
    {
        public static Expression<Func<ExamManage,bool>> GetExpression(this ExamManagePagedRequest examManagePagedRequest)
        {
            Expression<Func<ExamManage, bool>> expression = m => m.Id != null;

            expression = ExpressionableUtility.CreateExpression<ExamManage>()
                         .AndIF(examManagePagedRequest.Code.IsNotNullOrEmpty(), x => x.Code.Contains(examManagePagedRequest.Code))
                         .AndIF(examManagePagedRequest.Name.IsNotNullOrEmpty(), x => x.Name.Contains(examManagePagedRequest.Name))
                         .AndIF(examManagePagedRequest.ExamType.IsNotNull(), x => x.ExamType == examManagePagedRequest.ExamType)
                         .AndIF(examManagePagedRequest.Mode.IsNotNull(), x => x.Mode == examManagePagedRequest.Mode).ToExpression();

            return expression;
        }

        public static Expression<Func<ExamManage,bool>> GetExpression(this GenerateExamTestPaperRequest generateExamTestPaperRequest)
        {
            Expression<Func<ExamManage, bool>> expression = m => m.Id != null;

            expression = ExpressionableUtility.CreateExpression<ExamManage>()
                         .AndIF(generateExamTestPaperRequest.ExamManageId.IsNotNullOrEmpty(), x => x.Id == generateExamTestPaperRequest.ExamManageId)
                         .AndIF(generateExamTestPaperRequest.TestPaperId.IsNotNullOrEmpty(), x => x.TestPaperId == generateExamTestPaperRequest.TestPaperId)
                         .AndIF(generateExamTestPaperRequest.ExtractRuleId.IsNotNullOrEmpty(),x=>x.ExtractRuleId == generateExamTestPaperRequest.ExtractRuleId)
                         .ToExpression();

            return expression;
        }
    }
}
