""".

This is info messages file, contains all the info messages for the service

"""

from flask import jsonify
from core.handlers.common_handlers import base_response, base_response_token
from core.handlers.common_handlers import base_response_user
from core.messages import successful_messages as info
from flask_api import status


def correct_login(auth_token):
    """Return a json response with the description and http status 200."""
    return base_response_token(info.SUCCESS_HANDLER,
                               info.USER_LOGIN_OK,
                               status.HTTP_200_OK,
                               auth_token)


def correct_register(auth_token):
    """Return a json response with the description and http status 201."""
    return base_response_token(info.SUCCESS_HANDLER,
                               info.USER_REGISTER_OK,
                               status.HTTP_201_CREATED,
                               auth_token)


def correct_logout():
    """Return a json response with the description and http status 200."""
    return base_response(info.SUCCESS_HANDLER,
                         info.USER_LOGOUT_OK,
                         status.HTTP_200_OK)


def user_status(user):
    """Return a json response with the description and http status 200."""
    return base_response_user(info.SUCCESS_HANDLER,
                              status.HTTP_200_OK,
                              user)


def user_created(email):
    """Return a json response with the description and http status 201."""
    return base_response(info.SUCCESS_HANDLER,
                         email + info.USER_ADD_OK,
                         status.HTTP_201_CREATED)


def user_updated():
    """Return a json response with the description and http status 200."""
    return base_response(info.SUCCESS_HANDLER,
                         info.USER_UPDATE_OK,
                         status.HTTP_200_OK)


def user_read(user):
    """Return a json response with the description and http status 200."""
    return base_response_user(info.SUCCESS_HANDLER,
                              status.HTTP_202_ACCEPTED,
                              user)


def user_read_all(users):
    """Return a json response with the users list and sucess status."""
    users_list = []
    for user in users.items:
        user_object = {
            'id': user.id,
            'username': user.username,
            'email': user.email,
            'registered_on': user.registered_on,
            'is_active': user.is_active,
            'is_admin': user.is_admin
        }
        users_list.append(user_object)
    response_object = {
        'status': 'success',
        'data': {
            'users': users_list
        }
    }
    return jsonify(response_object), status.HTTP_200_OK
