from django.core import validators
from django.utils.deconstruct import deconstructible
from django.utils.translation import gettext_lazy as _


@deconstructible
class UnicodePhoneNumberValidator(validators.RegexValidator):
    regex = r"^([0-9]){11}$"
    message = _(
        "Enter a valid phone_number.\n"
        "Sample 09123456789"
    )
    flags = 0


def RNSL6(*args, **kwargs):
    # Random numeric string of length 6
    from random import choices

    ret = ''.join(choices('123456789', k=6))
    return ret


def RSL(*args, **kwargs):
    # Random  string
    from random import choices, randint
    import string

    ret = ''.join(choices("!#$&*-.@_" + string.ascii_letters + string.digits, k=randint(8, 15)))
    return ret


def request_updater(request, **kwargs):
    if hasattr(request, 'data') and request.data:
        request.data._mutable = True
        for k, v in kwargs.items():
            request.data[k] = v
        request.data._mutable = False
    return request
