using Exam.Infrastructure.Extensions;
using FluentValidation;
using Hotline.Exams.TestPapers;
using Hotline.Exams.Validate;
using Hotline.Share.Dtos.TestPapers;

namespace Hotline.Validators.Exams.TestPapers
{
    public class AddTestPaperDtoValidator:AbstractValidator<AddTestPaperDto>
    {
        public AddTestPaperDtoValidator()
        {
            RuleFor(m => m.Name).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTestPaper.Name))));
            RuleFor(m => m.Code).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTestPaper.Code))));
            RuleFor(m => m.ExamType).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTestPaper.ExamType))));
            RuleFor(m => m.Mode).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTestPaper.Mode))));

            RuleForEach(m => m.TestPaperItemDtos).SetValidator(new AddTestPaperItemDtoValidator());

            RuleForEach(m => m.TestPaperRuleDtos).SetValidator(new AddTestPaperRuleDtoValidator());
        }
    }
}
