import { FieldValidation } from '@/validation/protocols' ; import { Validation } from '@/presentation/protocols' ; export class ValidationComposite implements Validation { private constructor ( private readonly validators ) { } static build ( validators ) { return new ValidationComposite ( validators ) ; } validate ( fieldName , input ) { const validators = this . validators . filter ( v => v . field === fieldName ) ; for ( const validator of validators ) { const error = validator . validate ( input ) ; if ( error ) { return error . message ; } } } }