# Path: carrot/views.py
# class MessageList(TemplateView):
#     template_name = 'carrot/index.vue'
# 
# Path: carrot/utilities.py
# def decorate_class_view(view_class: object,
#                         decorators: List[str] = None) -> Any:
#     """
#     Loop through a list of string paths to decorator functions, and call :func:`.create_class_view` for each one
#     """
#     if decorators is None:
#         decorators = []
# 
#     for decorator in decorators:
#         _module = '.'.join(decorator.split('.')[:-1])
#         module = importlib.import_module(_module)
#         _decorator = getattr(module, decorator.split('.')[-1])
#         view_class = create_class_view(view_class, _decorator)
# 
#     return view_class
# 
# def decorate_function_view(view: Any, decorators: List[str] = None) -> Any:
#     """
#     Similar to :func:`.decorate_class_view`, but for function based views
#     """
#     if not decorators:
#         decorators = []
# 
#     for decorator in decorators:
#         _module = '.'.join(decorator.split('.')[:-1])
#         module = importlib.import_module(_module)
#         _decorator = getattr(module, decorator.split('.')[-1])
#         view = create_function_view(view, _decorator)
# 
#     return view
# 
# def create_class_view(view: Any, decorator: Any) -> object:
#     """
#     Applies a decorator to the dispatch method of a given class based view. Can be chained
#     """
#     mixin: Any = get_mixin(decorator)
#     base_view: Any = view
# 
#     class DecoratedView(mixin, base_view):
#         pass
# 
#     return DecoratedView
# 
# Path: carrot/api.py
# class MessageLogSerializer(serializers.ModelSerializer):
#     class Meta:
# class SmallPagination(pagination.PageNumberPagination):
# class MessageLogViewset(viewsets.ModelViewSet):
# class PublishedMessageLogViewSet(MessageLogViewset):
# class FailedMessageLogViewSet(MessageLogViewset):
# class CompletedMessageLogViewSet(MessageLogViewset):
# class MessageLogDetailViewset(MessageLogViewset):
# class ScheduledTaskSerializer(serializers.ModelSerializer):
#     class Meta:
# class ScheduledTaskViewset(viewsets.ModelViewSet):
#     def get_queryset(self) -> QuerySet:
#     def purge(self, request: Request, *args, **kwargs) -> response.Response:
#     def requeue(self, request: Request, *args, **kwargs) -> response.Response:
#     def destroy(self, request: Request, *args, **kwargs) -> response.Response:
#     def retry(self, request: Request, *args, **kwargs) -> response.Response:
#     def destroy(self, request: Request, *args, **kwargs) -> response.Response:
#     def retry(self, request: Request, *args, **kwargs) -> response.Response:
#     def validate_task(self, value: str) -> str:
#     def validate_task_args(self, value: str) -> str:
#     def validate_content(self, value: str) -> str:
#     def validate_queue(self, value: str) -> str:
#     def validate_args(self, request: Request, *args, **kwargs) -> response.Response:
#     def get_task_choices(self, request: Request, *args, **kwargs) -> response.Response:
#     def create(self, request: Request, *args, **kwargs) -> viewsets.ModelViewSet.create:
#     def update(self, request: Request, *args, **kwargs) -> viewsets.ModelViewSet.update:
#     def run(self, request: Request, *args, **kwargs) -> viewsets.ModelViewSet.retrieve:


from django.conf.urls import url
from carrot.views import MessageList
from carrot.utilities import decorate_class_view, decorate_function_view, create_class_view
from django.conf import settings
from carrot.api import (
    published_message_log_viewset, failed_message_log_viewset, completed_message_log_viewset, scheduled_task_viewset,
    detail_message_log_viewset, scheduled_task_detail, run_scheduled_task, task_list, validate_args, purge_messages,
    MessageLogViewset, requeue_pending
)
from typing import Any

try:
    decorators = settings.CARROT.get('monitor_authentication', [])
except AttributeError:
    decorators = []


def _(v: Any, **kwargs) -> Any:
    """
    Decorates a class based view with a custom auth decorator specified in the settings module
    """
    return decorate_class_view(v, decorators).as_view(**kwargs)


def _f(v: MessageLogViewset) -> Any:
    """
    The same as the above _ method, but for function-based views
    """
    return decorate_function_view(v, decorators)


urlpatterns = [
    url(r'^$', _(MessageList), name='carrot-monitor'),
    url(r'^api/message-logs/published/$', _f(published_message_log_viewset), name='published-messagelog'),
    url(r'^api/message-logs/failed/$', _f(failed_message_log_viewset)),

# Path: carrot/views.py
# class MessageList(TemplateView):
#     template_name = 'carrot/index.vue'
# 
# Path: carrot/utilities.py
# def decorate_class_view(view_class: object,
#                         decorators: List[str] = None) -> Any:
#     """
#     Loop through a list of string paths to decorator functions, and call :func:`.create_class_view` for each one
#     """
#     if decorators is None:
#         decorators = []
# 
#     for decorator in decorators:
#         _module = '.'.join(decorator.split('.')[:-1])
#         module = importlib.import_module(_module)
#         _decorator = getattr(module, decorator.split('.')[-1])
#         view_class = create_class_view(view_class, _decorator)
# 
#     return view_class
# 
# def decorate_function_view(view: Any, decorators: List[str] = None) -> Any:
#     """
#     Similar to :func:`.decorate_class_view`, but for function based views
#     """
#     if not decorators:
#         decorators = []
# 
#     for decorator in decorators:
#         _module = '.'.join(decorator.split('.')[:-1])
#         module = importlib.import_module(_module)
#         _decorator = getattr(module, decorator.split('.')[-1])
#         view = create_function_view(view, _decorator)
# 
#     return view
# 
# def create_class_view(view: Any, decorator: Any) -> object:
#     """
#     Applies a decorator to the dispatch method of a given class based view. Can be chained
#     """
#     mixin: Any = get_mixin(decorator)
#     base_view: Any = view
# 
#     class DecoratedView(mixin, base_view):
#         pass
# 
#     return DecoratedView
# 
# Path: carrot/api.py
# class MessageLogSerializer(serializers.ModelSerializer):
#     class Meta:
# class SmallPagination(pagination.PageNumberPagination):
# class MessageLogViewset(viewsets.ModelViewSet):
# class PublishedMessageLogViewSet(MessageLogViewset):
# class FailedMessageLogViewSet(MessageLogViewset):
# class CompletedMessageLogViewSet(MessageLogViewset):
# class MessageLogDetailViewset(MessageLogViewset):
# class ScheduledTaskSerializer(serializers.ModelSerializer):
#     class Meta:
# class ScheduledTaskViewset(viewsets.ModelViewSet):
#     def get_queryset(self) -> QuerySet:
#     def purge(self, request: Request, *args, **kwargs) -> response.Response:
#     def requeue(self, request: Request, *args, **kwargs) -> response.Response:
#     def destroy(self, request: Request, *args, **kwargs) -> response.Response:
#     def retry(self, request: Request, *args, **kwargs) -> response.Response:
#     def destroy(self, request: Request, *args, **kwargs) -> response.Response:
#     def retry(self, request: Request, *args, **kwargs) -> response.Response:
#     def validate_task(self, value: str) -> str:
#     def validate_task_args(self, value: str) -> str:
#     def validate_content(self, value: str) -> str:
#     def validate_queue(self, value: str) -> str:
#     def validate_args(self, request: Request, *args, **kwargs) -> response.Response:
#     def get_task_choices(self, request: Request, *args, **kwargs) -> response.Response:
#     def create(self, request: Request, *args, **kwargs) -> viewsets.ModelViewSet.create:
#     def update(self, request: Request, *args, **kwargs) -> viewsets.ModelViewSet.update:
#     def run(self, request: Request, *args, **kwargs) -> viewsets.ModelViewSet.retrieve:


# Path: carrot/urls.py
from django.conf.urls import url
from carrot.views import MessageList
from carrot.utilities import decorate_class_view, decorate_function_view, create_class_view
from django.conf import settings
from carrot.api import (
    published_message_log_viewset, failed_message_log_viewset, completed_message_log_viewset, scheduled_task_viewset,
    detail_message_log_viewset, scheduled_task_detail, run_scheduled_task, task_list, validate_args, purge_messages,
    MessageLogViewset, requeue_pending
)
from typing import Any


try:
    decorators = settings.CARROT.get('monitor_authentication', [])
except AttributeError:
    decorators = []


def _(v: Any, **kwargs) -> Any:
    """
    Decorates a class based view with a custom auth decorator specified in the settings module
    """
    return decorate_class_view(v, decorators).as_view(**kwargs)


def _f(v: MessageLogViewset) -> Any:
    """
    The same as the above _ method, but for function-based views
    """
    return decorate_function_view(v, decorators)


urlpatterns = [
    url(r'^$', _(MessageList), name='carrot-monitor'),
    url(r'^api/message-logs/published/$', _f(published_message_log_viewset), name='published-messagelog'),
    url(r'^api/message-logs/failed/$', _f(failed_message_log_viewset)),

    url(r'^api/message-logs/purge/$', _f(purge_messages)),