using FluentValidation;
using CMSMicroservice.Protobuf.Protos.UserWalletHistory;
namespace CMSMicroservice.Protobuf.Validator.UserWalletHistory;

public class UpdateUserWalletHistoryRequestValidator : AbstractValidator<UpdateUserWalletHistoryRequest>
{
    public UpdateUserWalletHistoryRequestValidator()
    {
        RuleFor(model => model.Id)
            .NotNull();
        RuleFor(model => model.WalletId)
            .NotNull();
        RuleFor(model => model.CurrentBalance)
            .NotNull();
        RuleFor(model => model.ChangeValue)
            .NotNull();
        RuleFor(model => model.CurrentNetworkBalance)
            .NotNull();
        RuleFor(model => model.ChangeNerworkValue)
            .NotNull();
        RuleFor(model => model.IsIncrease)
            .NotNull();
    }
    public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
    {
        var result = await ValidateAsync(ValidationContext<UpdateUserWalletHistoryRequest>.CreateWithOptions((UpdateUserWalletHistoryRequest)model, x => x.IncludeProperties(propertyName)));
        if (result.IsValid)
            return Array.Empty<string>();
        return result.Errors.Select(e => e.ErrorMessage);
    };
}
