using Exam.Infrastructure.Extensions;
using Exam.Infrastructure.Validation.Validation;
using FluentValidation;
using Hotline.Exams.ExamManages;
using Hotline.Exams.Questions;
using Hotline.Exams.Validate;
using Hotline.Repository.SqlSugar.Exam.Validate;
using ExamQuestionOptions = Hotline.Exams.Questions.ExamQuestionOptions;

namespace Hotline.Repository.SqlSugar.Exam.Validators.ExamManages
{
    public class UserExamItemOptionsValidator: BaseValidator<ExamUserExamItemOptions>
    {
        public UserExamItemOptionsValidator()
        {
            RuleSet(ValidatorTypeConstants.Create, () =>
            {
                BaseValidateRule();

                ValidateRuleWithAdd();
            });

            RuleSet(ValidatorTypeConstants.Modify, () =>
            {
                BaseValidateRule();

                ValidateRuleWithModify();
            });
        }

        protected override void BaseValidateRule()
        {
            base.BaseValidateRule();

            RuleFor(x => x.QuestionOptionId).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, typeof(ExamQuestionOptions).GetDescription()));

            RuleFor(x => x.UserExamItemId).NotEmpty().WithMessage(x=>string.Format(ExamErrorMessage.IsRequired,typeof(ExamUserExamItem).GetDescription()));
        }

        protected override void ValidateRuleWithAdd()
        {
            base.ValidateRuleWithAdd();
            RuleFor(m => m.CreationTime).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamUserExamItem.CreationTime))));
        }

        protected override void ValidateRuleWithModify()
        {
            base.ValidateRuleWithModify();
            RuleFor(m => m.LastModificationTime).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamUserExamItem.LastModificationTime))));

        }
    }
}
