package com.banesco.common.infraestructure.utils;

import java.util.regex.Pattern;

/**
 * Clase para validar Expresion regulares
 */
public class PatternValidator {

    private final Pattern pattern;

    public PatternValidator(String patternStr) {
        pattern = Pattern.compile(patternStr);
    }

    public static PatternValidator withRegex(String patternStr) {
        return new PatternValidator(patternStr);
    }

    /**
     * Validates is un valor tiene formato valido.
     *
     * @param value the value to check.
     * @return true if the value has format valid, false otherwise.
     */
    public boolean isValid(String value) {
        if (value == null) {
            return false;
        }
        return pattern.matcher(value).matches();
    }
}
