namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.UpdateFactorDetails;
public class UpdateFactorDetailsCommandValidator : AbstractValidator<UpdateFactorDetailsCommand>
{
    public UpdateFactorDetailsCommandValidator()
    {
        RuleFor(model => model.Id)
            .NotNull();
        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<UpdateFactorDetailsCommand>.CreateWithOptions((UpdateFactorDetailsCommand)model, x => x.IncludeProperties(propertyName)));
        if (result.IsValid)
            return Array.Empty<string>();
        return result.Errors.Select(e => e.ErrorMessage);
    };
}
