"""All Flask blueprints for the entire application.

All blueprints for all views go here. They shall be imported by the views themselves and by application.py. Blueprint
URL paths are defined here as well.
"""

from flask import Blueprint


def _factory(partial_module_string, url_prefix=None):
    """Generates blueprint objects for view modules.

    Positional arguments:
    partial_module_string -- string representing a view module without the absolute path (e.g. 'home.index' for
        pypi_portal.views.home.index).
    url_prefix -- URL prefix passed to the blueprint.

    Returns:
    Blueprint instance for a view module.
    """
    name = partial_module_string
    import_name = 'pritunl_dedicated.views.{}'.format(partial_module_string)
    template_folder = 'templates'
    blueprint = Blueprint(name, import_name, template_folder=template_folder, url_prefix=url_prefix)
    return blueprint


api_dedicated = _factory('api.dedicated', '/api/dedicated')
api_user = _factory('api.user', '/api/user')
api_subscription = _factory('api.subscription', '/api/subscription')
api_subscription_plan = _factory('api.subscription_plan', '/api/subscription-plan')
api_version = _factory('api.version', '/api/version')


all_blueprints = (
    api_dedicated,
    api_user,
    api_subscription,
    api_subscription_plan,
    api_version
)