from django.urls import path, re_path
from rest_framework.urlpatterns import format_suffix_patterns

# pylint: disable=no-name-in-module
from oscar.core.application import OscarConfig

from oscarapi.utils.loading import get_api_class, get_api_classes


class Oscar3ApiAppConfig(OscarConfig):
    name = "ocyan.plugin.oscar_checkout.checkoutapi"
    label = "checkoutapi"
    verbose_name = "Oscar api"
    namespace = "checkoutapi"

    def get_urls(self):
        from . import views

        LoginView = get_api_class("views.login", "LoginView")

        # pylint: disable=unbalanced-tuple-unpacking
        (BasketDetail, CountryList, CountryDetail) = get_api_classes(
            "views.basic", ["BasketDetail", "CountryList", "CountryDetail"]
        )

        UserAddressDetail = get_api_class("views.checkout", "UserAddressDetail")

        return format_suffix_patterns(
            [
                re_path(r"^$", views.api_root, name="api-root"),
                re_path(
                    r"^basket/shipping-methods/$",
                    views.ShippingMethodView.as_view(),
                    name="api-basket-shipping-methods",
                ),
                re_path(
                    r"^basket/total/$",
                    views.OrderTotalView.as_view(),
                    name="api-basket-total",
                ),
                re_path(
                    r"^basket/payment-methods/$",
                    views.PaymentMethodView.as_view(),
                    name="api-basket-payment-methods",
                ),
                path("login/", LoginView.as_view(), name="api-login"),
                path("baskets/<int:pk>/", BasketDetail.as_view(), name="basket-detail"),
                path("countries/", CountryList.as_view(), name="country-list"),
                re_path(
                    r"^countries/(?P<pk>[A-z]{2})/$",
                    CountryDetail.as_view(),
                    name="country-detail",
                ),
                path(
                    "useraddresses/<int:pk>/",
                    UserAddressDetail.as_view(),
                    name="useraddress-detail",
                ),
            ]
        )
