from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.urls import path


class CheckoutAppConfig:
    index_view = None
    cancel_view = None
    thankyou_view = None
    thankyou_from_link_view = None
    order_not_found_view = None
    try_again_view = None
    try_again_from_link_view = None

    def get_urls(self):
        # pylint: disable=no-member
        urls = [
            path("", self.index_view.as_view(), name="index"),
            path("cancel/", self.cancel_view.as_view(), name="cancel"),
            path("thank-you/", self.thankyou_view.as_view(), name="thank-you"),
            path(
                "thank-you/<oidb64>/<token>/",
                self.thankyou_from_link_view.as_view(),
                name="thank-you",
            ),
            path(
                "order-not-found/",
                self.order_not_found_view.as_view(),
                name="order-not-found",
            ),
            path("try-again/", self.try_again_view.as_view(), name="try-again"),
            path(
                "try-again/<oidb64>/<token>/",
                self.try_again_from_link_view.as_view(),
                name="try-again-from-link",
            ),
        ]
        return self.post_process_urls(urls)

    def get_url_decorator(self, pattern):
        if not settings.OSCAR_ALLOW_ANON_CHECKOUT:
            return login_required
        if pattern.name.startswith("user-address"):
            return login_required
        return None
