'''
Validators
'''

from __future__ import unicode_literals

from django.core.exceptions import ValidationError



REGEX_URL = r'(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9]\.[^\s]{2,})$'

'''Mobile Number Regex for 16 digit mobile number'''
REGEX_MOBILE_NUMBER = r'^\+?1?\d{9,16}$'

'''Youtube Url regex to validate youtube url'''
YOUTUBE_URL_REGEX = r'^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$'

'''validate Youtube video duration format'''
YOUTUBE_DURATION_REGEX = r'^PT((?P<hours>\d+)H)?((?P<minutes>\d+)M)?((?P<seconds>\d+)S)?$'

PASSWORD_REGEX = r'^.{6,15}$'

def validate_password(password):
    '''
    Validate Password
    Django provides a flexible password storage system.
    By default, Django uses the PBKDF2 algorithm with a
    SHA256 hash, a password stretching mechanism
    recommended by NIST.
    '''
    if password is None:
        raise ValidationError('this cannot be blank ',
                              code='required', params={'password': 'password'})
    elif len(password) < 6:
        raise ValidationError('Must have at least 6 chars ',
                              code='min_length', params={'password': 'password'})
    else:
        return password


