namespace CMSMicroservice.Application.ConfigurationCQ.Queries.GetConfigurationHistory;

public class GetConfigurationHistoryQueryValidator : AbstractValidator<GetConfigurationHistoryQuery>
{
    public GetConfigurationHistoryQueryValidator()
    {
        RuleFor(x => x.ConfigurationId)
            .GreaterThan(0)
            .WithMessage("شناسه Configuration معتبر نیست");
    }

    public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
    {
        var result = await ValidateAsync(
            ValidationContext<GetConfigurationHistoryQuery>.CreateWithOptions(
                (GetConfigurationHistoryQuery)model, 
                x => x.IncludeProperties(propertyName)));
        
        if (result.IsValid)
            return Array.Empty<string>();
        
        return result.Errors.Select(e => e.ErrorMessage);
    };
}
