export type ValidationOption = {
  value?: string | number
  errorMessage: string
}

export const validator = {
  email: (value: string) => value.length > 70 || !/^[\w%+-]+(\.[\w%+-]+)*@[\w%+-]+(\.[\w%+-]+)+$/.test(value),

  min: (value: string, options: ValidationOption) => {
    if (!options.value) {
      return false
    }

    if (Number(value)) {
      return options.value < Number(value)
    }
    return options.value < value.trim().length
  },
  max: (value: string, options: ValidationOption) => {
    if (!options.value) {
      return false
    }

    if (Number(value)) {
      return options.value > Number(value)
    }
    return options.value > value.trim().length
  },
}

export type ValidatorKeysType = keyof typeof validator

export type ValidationSchema = { [key in ValidatorKeysType]?: ValidationOption }
