# Path: models.py
# class User(BaseModel, UserMixin):
#     """
#     User represents an user for the application.
# 
#     Attributes:
#         first_name (str): User's first name
#         last_name (str): User's last name
#         email (str): User's **valid** email
#         password (str): User's password
#         admin (bool): User's admin status. Defaults to ``False``
# 
#     .. NOTE::
#         Each User resource must have an unique `email` field, meaning
#         that there cannot be two user's registered with the same email.
# 
#         For this reason, when checking for user's existence, the server requires
#         either the `uuid` of the user or its `email`.
#     """
#     uuid = UUIDField(unique=True)
#     first_name = CharField()
#     last_name = CharField()
#     email = CharField(unique=True)
#     password = CharField()
#     admin = BooleanField(default=False)
#     _schema = UserSchema
# 
#     @staticmethod
#     def exists(email):
#         """
#         Check that an user exists by checking the email field.
# 
#         Args:
#             email (str): User's email to check
#         """
#         try:
#             User.get(User.email == email)
#         except User.DoesNotExist:
#             return False
#         return True
# 
#     @staticmethod
#     def hash_password(password):
#         """
#         Use passlib to get a crypted password.
# 
#         Args:
#             password (str): password to hash
# 
#         Returns:
#             str: hashed password
#         """
#         return pbkdf2_sha256.hash(password)
# 
#     def verify_password(self, password):
#         """
#         Verify a clear password against the stored hashed password of the user
#         using passlib.
# 
#         Args:
#             password (str): Password to verify against the hashed stored password
#         Returns:
#             bool: wether the given email matches the stored one
#         """
#         return pbkdf2_sha256.verify(password, self.password)
# 
#     def add_favorite(user, item):
#         """Link the favorite item to user."""
#         return Favorite.create(
#             uuid=uuid4(),
#             item=item,
#             user=user,
#         )
# 
#     def delete_favorite(self, obj):
#         obj.delete_instance()
# 
# Path: utils.py
# def non_empty_str(val, name):
#     """
#     Check if a string is empty. If not, raise a ValueError exception.
#     """
#     if not str(val).strip():
#         raise ValueError('The argument {} is not empty'.format(name))
#     return str(val)


import click
import sys
import uuid
from models import User
from utils import non_empty_str
    if not email:
        email = click.prompt('Please enter a valid email')
    if not password:
        password = click.prompt('Please enter your password')

    request_data = {
        'first_name': first_name,
        'last_name': last_name,
        'email': email,
        'password': password
    }

    for field in request_data:
        try:
            value = request_data[field]
            non_empty_str(value, field)
        except ValueError:
            print('ERROR! Some fields are empty or required')
            sys.exit(-1)

    # If email is present in the database return a ERROR and close the program.
    if User.exists(request_data['email']):
        print('ERROR! email already exists')
        sys.exit(-1)

    User.create(
        uuid=uuid.uuid4(),
        first_name=first_name,
        last_name=last_name,
        email=email,

# Path: models.py
# class User(BaseModel, UserMixin):
#     """
#     User represents an user for the application.
# 
#     Attributes:
#         first_name (str): User's first name
#         last_name (str): User's last name
#         email (str): User's **valid** email
#         password (str): User's password
#         admin (bool): User's admin status. Defaults to ``False``
# 
#     .. NOTE::
#         Each User resource must have an unique `email` field, meaning
#         that there cannot be two user's registered with the same email.
# 
#         For this reason, when checking for user's existence, the server requires
#         either the `uuid` of the user or its `email`.
#     """
#     uuid = UUIDField(unique=True)
#     first_name = CharField()
#     last_name = CharField()
#     email = CharField(unique=True)
#     password = CharField()
#     admin = BooleanField(default=False)
#     _schema = UserSchema
# 
#     @staticmethod
#     def exists(email):
#         """
#         Check that an user exists by checking the email field.
# 
#         Args:
#             email (str): User's email to check
#         """
#         try:
#             User.get(User.email == email)
#         except User.DoesNotExist:
#             return False
#         return True
# 
#     @staticmethod
#     def hash_password(password):
#         """
#         Use passlib to get a crypted password.
# 
#         Args:
#             password (str): password to hash
# 
#         Returns:
#             str: hashed password
#         """
#         return pbkdf2_sha256.hash(password)
# 
#     def verify_password(self, password):
#         """
#         Verify a clear password against the stored hashed password of the user
#         using passlib.
# 
#         Args:
#             password (str): Password to verify against the hashed stored password
#         Returns:
#             bool: wether the given email matches the stored one
#         """
#         return pbkdf2_sha256.verify(password, self.password)
# 
#     def add_favorite(user, item):
#         """Link the favorite item to user."""
#         return Favorite.create(
#             uuid=uuid4(),
#             item=item,
#             user=user,
#         )
# 
#     def delete_favorite(self, obj):
#         obj.delete_instance()
# 
# Path: utils.py
# def non_empty_str(val, name):
#     """
#     Check if a string is empty. If not, raise a ValueError exception.
#     """
#     if not str(val).strip():
#         raise ValueError('The argument {} is not empty'.format(name))
#     return str(val)


# Path: scripts/create_superuser.py
import click
import sys
import uuid
from models import User
from utils import non_empty_str

    if not email:
        email = click.prompt('Please enter a valid email')
    if not password:
        password = click.prompt('Please enter your password')

    request_data = {
        'first_name': first_name,
        'last_name': last_name,
        'email': email,
        'password': password
    }

    for field in request_data:
        try:
            value = request_data[field]
            non_empty_str(value, field)
        except ValueError:
            print('ERROR! Some fields are empty or required')
            sys.exit(-1)

    # If email is present in the database return a ERROR and close the program.
    if User.exists(request_data['email']):
        print('ERROR! email already exists')
        sys.exit(-1)

    User.create(
        uuid=uuid.uuid4(),
        first_name=first_name,
        last_name=last_name,
        email=email,

        password=User.hash_password(password),