from django.conf.urls import url
from django.urls import path

from oscar.core.application import DashboardApplication
from oscar.core.loading import get_class


class OrdersDashboardApplication(DashboardApplication):
    name = None
    default_permissions = ['is_staff', ]
    permissions_map = {
        'order-list': (['is_staff'], ['partner.dashboard_access']),
        # filtered order lists
        'order-list-coffee': (['is_staff'], ['partner.dashboard_access']),
        'order-list-pods': (['is_staff'], ['partner.dashboard_access']),
        'order-list-gears': (['is_staff'], ['partner.dashboard_access']),
        'order-list-workshops': (['is_staff'], ['partner.dashboard_access']),
        'order-list-hook-bags': (['is_staff'], ['partner.dashboard_access']),
        'order-list-multiple': (['is_staff'], ['partner.dashboard_access']),
        'order-list-declined': (['is_staff'], ['partner.dashboard_access']),

        'order-stats': (['is_staff'], ['partner.dashboard_access']),
        'order-detail': (['is_staff'], ['partner.dashboard_access']),
        'process-order': (['is_staff'], ['partner.dashboard_access']),
        'order-detail-note': (['is_staff'], ['partner.dashboard_access']),
        'order-line-detail': (['is_staff'], ['partner.dashboard_access']),
        'order-shipping-address': (['is_staff'], ['partner.dashboard_access']),
        'print-shipping-address': (['is_staff'], ['partner.dashboard_access']),
        'order-print-product-labels': (['is_staff'], ['partner.dashboard_access']),
        'process-shipment': (['is_staff'], ['partner.dashboard_access']),
        'out-of-coffee': (['is_staff'], ['partner.dashboard_access']),
    }

    order_list_view = get_class('dashboard.orders.views', 'OrderListView')

    # filtered order lists
    order_list_view_coffee = get_class('dashboard.orders.views', 'CoffeeOrderListView')
    order_list_view_pods = get_class('dashboard.orders.views', 'PodsOrderListView')
    order_list_view_gears = get_class('dashboard.orders.views', 'GearsOrderListView')
    order_list_view_workshops = get_class('dashboard.orders.views', 'WorkshopOrderListView')
    order_list_view_hook_bags = get_class('dashboard.orders.views', 'HookBagsOrderListView')
    order_list_view_multiple = get_class('dashboard.orders.views', 'MultipleOrderListView')
    order_list_view_declined = get_class('dashboard.orders.views', 'DeclinedOrderListView')

    order_detail_view = get_class('dashboard.orders.views', 'OrderDetailView')
    process_order_view = get_class('dashboard.orders.views', 'ProcessOrderView')
    shipping_address_view = get_class('dashboard.orders.views',
                                      'ShippingAddressUpdateView')
    line_detail_view = get_class('dashboard.orders.views', 'LineDetailView')
    order_stats_view = get_class('dashboard.orders.views', 'OrderStatsView')
    print_shipping_address = get_class('dashboard.orders.views', 'ShippingAddressView')
    process_shipment = get_class('dashboard.orders.views', 'ProcessShipmentView')
    print_product_labels = get_class('dashboard.orders.views', 'ProductLabelView')
    out_of_coffee = get_class('dashboard.orders.views', 'OutOfCoffeeView')

    def get_urls(self):
        urls = [
            url(r'^$', self.order_list_view.as_view(), name='order-list'),

            # filtered order lists
            path('coffees', self.order_list_view_coffee.as_view(), name='order-list-coffees'),
            path('pods', self.order_list_view_pods.as_view(), name='order-list-pods'),
            path('gears', self.order_list_view_gears.as_view(), name='order-list-gears'),
            path('workshops', self.order_list_view_workshops.as_view(), name='order_list_view_workshops'),
            path('hook-bags', self.order_list_view_hook_bags.as_view(), name='order-list-hook-bags'),
            path('multiple', self.order_list_view_multiple.as_view(), name='order-list-multiple'),
            path('declined', self.order_list_view_declined.as_view(), name='order-list-declined'),
            path('process-shipment', self.process_shipment.as_view(), name='process-shipment'),
            path('out-of-coffee', self.out_of_coffee.as_view(), name='out-of-coffee'),
            path('process-order/<pk>', self.process_order_view.as_view(), name='process-order'),

            url(r'^statistics/$', self.order_stats_view.as_view(), name='order-stats'),
            url(r'^(?P<number>[-\w]+)/$', self.order_detail_view.as_view(), name='order-detail'),
            url(r'^(?P<number>[-\w]+)/notes/(?P<note_id>\d+)/$', self.order_detail_view.as_view(),
                name='order-detail-note'),
            url(r'^(?P<number>[-\w]+)/lines/(?P<line_id>\d+)/$', self.line_detail_view.as_view(),
                name='order-line-detail'),
            url(r'^(?P<number>[-\w]+)/shipping-address/$', self.shipping_address_view.as_view(),
                name='order-shipping-address'),
            url(r'^(?P<number>[-\w]+)/print-shipping-address/$', self.print_shipping_address.as_view(),
                name='print-shipping-address'),
            url(r'^(?P<number>[-\w]+)/print-product-labels/$', self.print_product_labels.as_view(),
                name='order-print-product-labels'),
        ]
        return self.post_process_urls(urls)


application = OrdersDashboardApplication()
