namespace CMSMicroservice.Application.ProductCategoryCQ.Commands.UpdateProductCategory;
public class UpdateProductCategoryCommandValidator : AbstractValidator<UpdateProductCategoryCommand>
{
    public UpdateProductCategoryCommandValidator()
    {
        RuleFor(model => model.Id)
            .NotNull();
        RuleFor(model => model.ProductId)
            .NotNull();
        RuleFor(model => model.CategoryId)
            .NotNull();
    }
    public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
    {
        var result = await ValidateAsync(ValidationContext<UpdateProductCategoryCommand>.CreateWithOptions((UpdateProductCategoryCommand)model, x => x.IncludeProperties(propertyName)));
        if (result.IsValid)
            return Array.Empty<string>();
        return result.Errors.Select(e => e.ErrorMessage);
    };
}
