namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.CreateNewFactorDetails;
public class CreateNewFactorDetailsCommandValidator : AbstractValidator<CreateNewFactorDetailsCommand>
{
    public CreateNewFactorDetailsCommandValidator()
    {
        RuleFor(model => model.ProductId)
            .NotNull();
        RuleFor(model => model.Count)
            .NotNull();
        RuleFor(model => model.UnitPrice)
            .NotNull();
        RuleFor(model => model.UnitDiscount)
            .NotNull();
        RuleFor(model => model.OrderId)
            .NotNull();
        RuleFor(model => model.UnitDiscountPrice)
            .NotNull();
        RuleFor(model => model.IsChangePrice)
            .NotNull();
    }
    public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
    {
        var result = await ValidateAsync(ValidationContext<CreateNewFactorDetailsCommand>.CreateWithOptions((CreateNewFactorDetailsCommand)model, x => x.IncludeProperties(propertyName)));
        if (result.IsValid)
            return Array.Empty<string>();
        return result.Errors.Select(e => e.ErrorMessage);
    };
}
