import {validateField} from '../index.js'
import * as v from 'valibot'
import {valibotCheck} from '../../utils/index.js'

/**
 * Interface to define a Validator
 */
interface PayloadValidatorWithRegex {
  value: any
  regExp: RegExp,
  message?: string
}

/**
 * Wrapper function for Regex validation
 * @param regExp the regular expression to check
 * @param value the input to be checked
 * @param message message to shown if input is invalid
 */
export function validateRegex({value, regExp, message}: PayloadValidatorWithRegex): any {
  return validateField({
    condition: regExp.test(value) == false,
    message: message || 'Invalid input',
  })
}
