import { Validator , AllowedMimeTypes , Extension , MaxFileSize , Required , RequiredBuffer , RequiredString } from '@/application/validation' ; export class ValidationBuilder { private constructor ( private readonly value , private readonly fieldName ? , private readonly validators = [ ] ) { } static of ( { value , fieldName } ) { return new ValidationBuilder ( value , fieldName ) ; } required ( ) { if ( this . value instanceof Buffer ) { this . validators . push ( new RequiredBuffer ( this . value , this . fieldName ) ) ; } else if ( typeof this . value === 'string' ) { this . validators . push ( new RequiredString ( this . value , this . fieldName ) ) ; } else { this . validators . push ( new Required ( this . value , this . fieldName ) ) ; if ( this . value . buffer !== undefined ) { this . validators . push ( new RequiredBuffer ( this . value . buffer , this . fieldName ) ) ; } } return this ; } image ( { allowed , maxSizeInMb } ) { if ( this . value . mimeType !== undefined ) { this . validators . push ( new AllowedMimeTypes ( allowed , this . value . mimeType ) ) ; } if ( this . value . buffer !== undefined ) { this . validators . push ( new MaxFileSize ( maxSizeInMb , this . value . buffer ) ) ; } return this ; } build ( ) { return this . validators ; } }