using System.Collections.Generic;
using System.Linq;
using NodePipeline.Abstractions.Models.Validation;

namespace NodePipeline.Abstractions;

public static class ValidationHelper
{
    public static bool IsValid(ValidationResult validationResult, bool treatWarningsAsErrors)
    {
        return validationResult == ValidationResult.Valid
               || (!treatWarningsAsErrors && validationResult == ValidationResult.HasWarnings);
    }

    public static bool IsValid(IEnumerable<ValidationResult> validationResults, bool treatWarningsAsErrors)
    {
        return validationResults.All(validationResult => IsValid(validationResult, treatWarningsAsErrors));
    }
}