# Path: m2core/common/options.py
# class M2OptionParser(OptionParser):
#     def parse_environment(self, final=True):
# 
# Path: example/common/permissions.py
# class PlatformPermissions(PermissionsEnum):
#     AUTHORIZED = Permission(
#         name='Authorized users',
#         sys_name='authorized',
#         description='All authorized users will have this permission by default (overwrites default `AUTHORIZED` '
#                     'permission)'
#     )
#     VIEW_SOME_INFO = Permission(
#         name='View some info',
#         sys_name='view_some_info',
#         description='Example of some view permissions'
#     )
#     EDIT_SOME_INFO = Permission(
#         name='Edit some info',
#         sys_name='edit_some_info',
#         description='Example of some edit permissions'
#     )
#     DELETE_SOME_INFO = Permission(
#         name='Delete some info',
#         sys_name='delete_some_info',
#         description='Example of some delete permissions'
#     )
#     ADMIN = Permission(
#         name='Admin privilege',
#         sys_name='admin',
#         description='Example of admin (super user) permissions'
#     )
# 
# Path: m2core/m2core.py
# class M2Core:
#     def requires_permission(handler_method_func):
#         def decorated(handler_instance, *args, **kwargs):
#     def user_can(handler_method):
#         def decorated(handler_instance, *args, **kwargs):
#     def tryex(*errors):
#         def decorator(func):
#             def new_func(handler, *args, **kwargs):
#     def __recreate_db(self):
#     def __init__(self):
#     def __make_app(self):
#     def route(self, human_route: str=None, handler_cls: Type[RequestHandler]=None, rule_group: str=None,
#               extra: dict=None, **kwargs):
#     def add_endpoint(self, human_route: str, handler_class: Type[RequestHandler], extra_params: dict = dict()):
#     def add_endpoint_method_permissions(self, human_route: str, method: str, permissions: list or None):
#     def add_endpoint_permissions(self, human_route: str, permissions: dict):
#     def add_redis_scheme(self, _redis_scheme: dict):
#     def thread_pool(self) -> ThreadPoolExecutor:
#     def db_engine(self) -> Engine:
#     def db_session(self) -> scoped_session:
#     def redis_session(self) -> redis.StrictRedis:
#     def redis_tables(self) -> dict:
#     def app(self) -> tornado.web.Application:
#     def __make_db_session(self):
#     def __make_thread_pool(self):
#     def __make_redis_session(self):
#     def add_callback(self, callback: callable, *args, **kwargs):
#     def extended(self, callback: callable):
#         def call_me_maybe(*args, **kwargs):
#     def add_custom_response_headers(self, headers: dict()):
#     def run(self):
#     def run_with_recreate(self):
#     def run_for_test(self) -> tornado.web.Application:
#     def add_test_user(self, at: str, user_id: int=None, permissions: set=None):
#     def get_test_user(self, at: str) -> dict:
# def sync_permissions():
# def dump_roles():


from m2core.common.options import options
from example.handlers import *
from example.common.permissions import PlatformPermissions
from m2core import M2Core, logger as core_logger
from tornado.gen import coroutine, sleep
import logging
# import all handlers
# import permissions
# import core


# INIT M2CORE
options.config_name = 'config.py'
m2core = M2Core()


if __name__ == '__main__':

    # setup core logger level
    core_logger.setLevel(logging.DEBUG)
    # setup project logger
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)

    # add some headers per every response - CORS in this example
    m2core.add_custom_response_headers({
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS',
        'Access-Control-Expose-Headers': '',
        'Access-Control-Max-Age': '1728000',
        'Access-Control-Allow-Headers': 'Content-Type, X-Access-Token'
    })

    # ENDPOINTS
    human_route = r'/docs.js'

# Path: m2core/common/options.py
# class M2OptionParser(OptionParser):
#     def parse_environment(self, final=True):
# 
# Path: example/common/permissions.py
# class PlatformPermissions(PermissionsEnum):
#     AUTHORIZED = Permission(
#         name='Authorized users',
#         sys_name='authorized',
#         description='All authorized users will have this permission by default (overwrites default `AUTHORIZED` '
#                     'permission)'
#     )
#     VIEW_SOME_INFO = Permission(
#         name='View some info',
#         sys_name='view_some_info',
#         description='Example of some view permissions'
#     )
#     EDIT_SOME_INFO = Permission(
#         name='Edit some info',
#         sys_name='edit_some_info',
#         description='Example of some edit permissions'
#     )
#     DELETE_SOME_INFO = Permission(
#         name='Delete some info',
#         sys_name='delete_some_info',
#         description='Example of some delete permissions'
#     )
#     ADMIN = Permission(
#         name='Admin privilege',
#         sys_name='admin',
#         description='Example of admin (super user) permissions'
#     )
# 
# Path: m2core/m2core.py
# class M2Core:
#     def requires_permission(handler_method_func):
#         def decorated(handler_instance, *args, **kwargs):
#     def user_can(handler_method):
#         def decorated(handler_instance, *args, **kwargs):
#     def tryex(*errors):
#         def decorator(func):
#             def new_func(handler, *args, **kwargs):
#     def __recreate_db(self):
#     def __init__(self):
#     def __make_app(self):
#     def route(self, human_route: str=None, handler_cls: Type[RequestHandler]=None, rule_group: str=None,
#               extra: dict=None, **kwargs):
#     def add_endpoint(self, human_route: str, handler_class: Type[RequestHandler], extra_params: dict = dict()):
#     def add_endpoint_method_permissions(self, human_route: str, method: str, permissions: list or None):
#     def add_endpoint_permissions(self, human_route: str, permissions: dict):
#     def add_redis_scheme(self, _redis_scheme: dict):
#     def thread_pool(self) -> ThreadPoolExecutor:
#     def db_engine(self) -> Engine:
#     def db_session(self) -> scoped_session:
#     def redis_session(self) -> redis.StrictRedis:
#     def redis_tables(self) -> dict:
#     def app(self) -> tornado.web.Application:
#     def __make_db_session(self):
#     def __make_thread_pool(self):
#     def __make_redis_session(self):
#     def add_callback(self, callback: callable, *args, **kwargs):
#     def extended(self, callback: callable):
#         def call_me_maybe(*args, **kwargs):
#     def add_custom_response_headers(self, headers: dict()):
#     def run(self):
#     def run_with_recreate(self):
#     def run_for_test(self) -> tornado.web.Application:
#     def add_test_user(self, at: str, user_id: int=None, permissions: set=None):
#     def get_test_user(self, at: str) -> dict:
# def sync_permissions():
# def dump_roles():


# Path: example/run_me.py
from m2core.common.options import options
from example.handlers import *
from example.common.permissions import PlatformPermissions
from m2core import M2Core, logger as core_logger
from tornado.gen import coroutine, sleep
import logging

# import all handlers
# import permissions
# import core


# INIT M2CORE
options.config_name = 'config.py'
m2core = M2Core()


if __name__ == '__main__':

    # setup core logger level
    core_logger.setLevel(logging.DEBUG)
    # setup project logger
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)

    # add some headers per every response - CORS in this example
    m2core.add_custom_response_headers({
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS',
        'Access-Control-Expose-Headers': '',
        'Access-Control-Max-Age': '1728000',
        'Access-Control-Allow-Headers': 'Content-Type, X-Access-Token'
    })

    # ENDPOINTS
    human_route = r'/docs.js'

    m2core.route(human_route, RestApiDocsHandler, get=PlatformPermissions.SKIP)