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 ExtractRuleQueryExtensions
    {
        public static Expression<Func<ExamExtractRule, bool>> GetExpression(this ExtractRulePagedRequest extractRulePagedRequest)
        {
            Expression<Func<ExamExtractRule, bool>> expression = m => m.Id != null;

            expression = ExpressionableUtility.CreateExpression<ExamExtractRule>()
                         .AndIF(extractRulePagedRequest.Code.IsNotNullOrEmpty(), x => x.Code.Contains(extractRulePagedRequest.Code))
                         .AndIF(extractRulePagedRequest.Name.IsNotNullOrEmpty(), x => x.Name.Contains(extractRulePagedRequest.Name))
                         .AndIF(extractRulePagedRequest.ExamType.IsNotNull(), x => x.RuleType == extractRulePagedRequest.ExamType)
                         .AndIF(extractRulePagedRequest.Status.IsNotNull(), x => x.Status == extractRulePagedRequest.Status).ToExpression();

            return expression;
        }
    }
}
