# Path: core/classes/response.py
# class Response(object):
#     def __init__(self, has_error = True, content = {}, code=None):
#         super(Response, self).__init__()
#         self.has_error = has_error
#         self.content = content
#         self.code = code
#     #---------------------------------------------------------------------------
#     # json
#     #---------------------------------------------------------------------------
#     def json(self):
#         return {
#             'has_error': self.has_error, 
#             'content': self.content, 
#             'code': self.code
#         }
#     #---------------------------------------------------------------------------
#     # dumps
#     #---------------------------------------------------------------------------
#     def dumps(self, indent=None):
#         return json.dumps(self.json(), indent=indent)


import time
from flask_responses        import json_response
from flask                  import session
from functools              import wraps
from core.classes.response  import Response
from core.modules           import logger
# DECORATORS
#===============================================================================
#-------------------------------------------------------------------------------
# internal_error_handler
#-------------------------------------------------------------------------------
def internal_error_handler(err_code):
    def wrapper(f):
        @wraps(f)
        def wrapped_f(*args, **kwargs):
            try:
                return f(*args, **kwargs)
            except Exception as e:
                timestamp = time.strftime('%d%m%H%M%S')
                desc = '`mapif.{0}()` at `{1}` error: details below.'.format(
                    f.__name__, timestamp
                )
                modlgr.exception(desc)
                code = '{0}.{1}'.format(err_code, timestamp)
                resp = Response(has_error=True, code=code, content='')
                return json_response(resp.json(), status_code=500)
        return wrapped_f
    return wrapper
#-------------------------------------------------------------------------------
# require_connected
#-------------------------------------------------------------------------------
def require_connected():
    def wrapper(f):
        @wraps(f)
        def wrapped_f(*args, **kwargs):
            if not session.get('user', None):

# Path: core/classes/response.py
# class Response(object):
#     def __init__(self, has_error = True, content = {}, code=None):
#         super(Response, self).__init__()
#         self.has_error = has_error
#         self.content = content
#         self.code = code
#     #---------------------------------------------------------------------------
#     # json
#     #---------------------------------------------------------------------------
#     def json(self):
#         return {
#             'has_error': self.has_error, 
#             'content': self.content, 
#             'code': self.code
#         }
#     #---------------------------------------------------------------------------
#     # dumps
#     #---------------------------------------------------------------------------
#     def dumps(self, indent=None):
#         return json.dumps(self.json(), indent=indent)


# Path: core/modules/wrappers.py
import time
from flask_responses        import json_response
from flask                  import session
from functools              import wraps
from core.classes.response  import Response
from core.modules           import logger

# DECORATORS
#===============================================================================
#-------------------------------------------------------------------------------
# internal_error_handler
#-------------------------------------------------------------------------------
def internal_error_handler(err_code):
    def wrapper(f):
        @wraps(f)
        def wrapped_f(*args, **kwargs):
            try:
                return f(*args, **kwargs)
            except Exception as e:
                timestamp = time.strftime('%d%m%H%M%S')
                desc = '`mapif.{0}()` at `{1}` error: details below.'.format(
                    f.__name__, timestamp
                )
                modlgr.exception(desc)
                code = '{0}.{1}'.format(err_code, timestamp)
                resp = Response(has_error=True, code=code, content='')
                return json_response(resp.json(), status_code=500)
        return wrapped_f
    return wrapper
#-------------------------------------------------------------------------------
# require_connected
#-------------------------------------------------------------------------------
def require_connected():
    def wrapper(f):
        @wraps(f)
        def wrapped_f(*args, **kwargs):
            if not session.get('user', None):

                resp = Response(True, "Opération interdite vous n'êtes pas connecté !")