using DocumentFormat.OpenXml.Presentation;
using Exam.Infrastructure.Extensions;
using Hotline.Share.Requests.Train;
using JiebaNet.Segmenter.Common;
using System.Linq.Expressions;
using Hotline.Application.Exam.Core.Utilities;
using Hotline.Exams.Trains;

namespace Hotline.Application.Exam.QueryExtensions.Trains
{
    public static class TrainTemplateQueryExtensions
    {
        public static Expression<Func<ExamTrainTemplate,bool>> GetExpression(this TrainTemplatePagedRequest trainTemplatePagedRequest)
        {
            Expression<Func<ExamTrainTemplate, bool>> expression = m => m.Id!=null;

            expression = ExpressionableUtility.CreateExpression<ExamTrainTemplate>()
                .AndIF(trainTemplatePagedRequest.Code.IsNotNullOrEmpty(), x => x.Code.Contains(trainTemplatePagedRequest.Code))
                .AndIF(trainTemplatePagedRequest.Name.IsNotNullOrEmpty(), x => x.Name.Contains(trainTemplatePagedRequest.Name))
                .AndIF(trainTemplatePagedRequest.IsContainsPractice.IsNotNull(), x => x.IsContainsPractice == trainTemplatePagedRequest.IsContainsPractice)
                .AndIF(trainTemplatePagedRequest.Status.IsNotNull(),x=>x.Status==trainTemplatePagedRequest.Status)
                .AndIF(trainTemplatePagedRequest.MinCreationTime.IsNotNull(), x => x.CreationTime >= trainTemplatePagedRequest.MinCreationTime)
                .AndIF(trainTemplatePagedRequest.MaxCreationTime.IsNotNull(),x=>x.CreationTime<= trainTemplatePagedRequest.MaxCreationTime)
                .AndIF(trainTemplatePagedRequest.CreatorName.IsNotNullOrEmpty(), x => x.CreatorName == trainTemplatePagedRequest.CreatorName)
                .ToExpression();

            return expression;
        }
    }
}
