using Exam.Infrastructure.Extensions;
using Exam.Infrastructure.Validation.Validation;
using FluentValidation;
using Hotline.Exams.Trains;
using Hotline.Exams.Validate;
using Hotline.Repository.SqlSugar.Exam.Validate;
using Hotline.Users;

namespace Exam.Repository.Sqlsugar.Validators.Trains
{
    public class TrainRecordValidator:BaseValidator<ExamTrainRecord>
    {
        public TrainRecordValidator()
        {
            RuleSet(ValidatorTypeConstants.Create, () =>
            {
                BaseValidateRule();

                ValidateRuleWithAdd();
            });

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

                ValidateRuleWithModify();
            });
        }

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

            RuleFor(m=>m.UserId).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, typeof(User).GetDescription()));
        }

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

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

        }

    }
}
