using FluentValidation; using Indotalent.Shared.Consts; namespace Indotalent.Features.Pipeline.Lead.Cqrs; public class CreateLeadValidator : AbstractValidator { public CreateLeadValidator() { RuleFor(x => x.Title) .NotEmpty().WithMessage("Lead Title is required") .MaximumLength(GlobalConsts.StringLengthShort); RuleFor(x => x.CompanyName) .NotEmpty().WithMessage("Company Name is required") .MaximumLength(GlobalConsts.StringLengthShort); RuleFor(x => x.CompanyEmail) .EmailAddress().When(x => !string.IsNullOrEmpty(x.CompanyEmail)); RuleFor(x => x.CampaignId) .NotEmpty().WithMessage("Campaign is required"); RuleFor(x => x.SalesTeamId) .NotEmpty().WithMessage("Sales Team is required"); } public Func>> ValidateValue() => async (model, propertyName) => { var result = await ValidateAsync(ValidationContext.CreateWithOptions((CreateLeadRequest)model, x => x.IncludeProperties(propertyName))); if (result.IsValid) return Array.Empty(); return result.Errors.Select(e => e.ErrorMessage); }; }