public async Task <ValidationMessages> ValidateAsync(
            FormResponse template,
            Submission submission
            )
        {
            var fields = template
                         .Sections
                         .SelectMany(x => x.Groups)
                         .SelectMany(x => x.Fields)
                         .Select(field => new
            {
                name       = field.Name,
                validators = field.Validators
                             .SelectMany
                             (
                    definition => validators
                    .Where(y => y.Name == definition.Name &&
                           definition.Conditions.All(c => conditions.Where(co => co.Name == c).Any(p => p.Evaluate(submission))))
                    .ToList()
                             )
            })
                         .ToList();

            var validationMessages = new ValidationMessages();

            foreach (var field in fields)
            {
                var messages = new List <string>();
                foreach (var validator in field.validators)
                {
                    var result = await validator.ValidateAsync(field.name, template, submission);

                    if (result == null)
                    {
                        continue;
                    }

                    messages.Add(result.ErrorMessage);
                }

                if (messages.Count > 0)
                {
                    validationMessages.Errors.Add(new ValidationMessage
                    {
                        Field    = field.name,
                        Messages = messages
                    });
                }
            }

            return(validationMessages);
        }
        public override Task <ValidationResult> ValidateAsync(
            string fieldName,
            FormResponse template,
            Submission submission)
        {
            var value = Get(fieldName, submission);

            switch (value)
            {
            case null:
            case string s when string.IsNullOrEmpty(s):
                return(Task.FromResult(new ValidationResult("Required", new[] { fieldName })));

            default:
                return(Task.FromResult(ValidationResult.Success));
            }
        }
 public abstract Task <ValidationResult> ValidateAsync(
     string fieldName,
     FormResponse template,
     Submission submission
     );