from .. import base

class IsAlpha(base.And):
	''' Accepts only strings with alphabetical characters, spaces, underscores or dashes '''

	def __init__(self):
		super(IsAlpha, self).__init__(
			base.types.ToType(unicode),
			base.strings.IsRegexMatch(base.canonicals.ALPHA_RE),
			error_message='The specified value "{value}" is not a purely alphabetical string.'
		)

class IsAlphaNumeric(base.And):
	''' Accepts only strings with alphabetical characters, spaces and dashes '''

	def __init__(self):
		super(IsAlphaNumeric, self).__init__(
			base.types.ToType(unicode),
			base.strings.IsRegexMatch(base.canonicals.ALNUM_RE),
			error_message='The specified value "{value}" is not a purely alphanumeric string.'
		)

class IsNumeric(base.And):
	''' Ensures only a numeric string '''

	def __init__(self):
		super(IsNumeric, self).__init__(
			base.types.ToType(unicode),
			base.strings.IsRegexMatch(base.canonicals.NUMERIC_RE),
			error_message='The specified value "{value}" is not a purely numerical string.'
		)

class IsText(base.And):
	''' Ensures a valid set of text like characters for descriptions. Includes acceptable punctuation. '''

	def __init__(self):
		super(IsText, self).__init__(
			base.types.ToType(unicode),
			base.strings.IsRegexMatch(base.canonicals.TEXT_RE),
			error_message='The specified value "{value}" is not pure text.'
		)

class IsName(base.And):
	'''
	Checks to make sure the string is a name. In otherwords,
	no numbers, symbols, or wierd punctuation.
	'''

	def __init__(self):
		super(IsName, self).__init__(
			base.types.ToType(unicode),
			base.strings.IsRegexMatch(r'^[a-z\s\.]+$'),
			error_message='The specified value "{value}" is not a valid name.'
		)


class ToYesOrNo(base.And):
	'''
	Determines whether input is affirmative or negative based on
	the common English language interpretations of words and
	abbreviations as defined in the canonicals module.
		
	'''

	def __init__(self):
		super(ToYesOrNo, self).__init__(
			base.IfElse(
				base.types.IsType(bool),
				base.And(base.types.ToType(unicode), base.strings.ToCanonical(), base.vocabulary.Synonyms(base.canonicals.TRUE_FALSE_DICT))
			),
			error_message='The specified value "{value}" could not be converted to a simple Yes or No.'
		)

from . import commerce, web