# -*- coding: utf-8 -*-
from django.urls import include, path

from ocyan.core.fender import config
from ocyan.mollie.constants import get_mollie_payments
from ocyan.plugin.oscar_checkout.plugins import PaymentPluginConfig

from .constants import APP_CODE

SHOP_BASE_URL = config.get("oscar", "shop_base_url", "shop")


class PaymentMollieConfig(PaymentPluginConfig):
    def contribute_to_installed_apps(self, installed_apps):
        installed_apps.ocyan.append("ocyan.plugin.payment_mollie")
        installed_apps.oscar.append(
            "ocyan.plugin.payment_mollie.mollie_order_ext",
            extends="ocyan.plugin.oscar_order.order",
        )
        installed_apps.oscar.append(
            "ocyan.plugin.payment_mollie.mollie_order_ext",
            extends="ocyan.plugin.oscar_paid_product_options.order_ppo_extension",
        )
        return installed_apps

    def contribute_to_payment_methods(self, payment_methods):
        return payment_methods + get_mollie_payments(APP_CODE, [], True)

    def contribute_to_urlpatterns(self, urlpatterns):
        new_patterns = [
            path(
                r"%s/" % SHOP_BASE_URL,
                include("ocyan.plugin.payment_mollie.urls", namespace=APP_CODE),
            )
        ]
        new_patterns.extend(list(urlpatterns))
        return new_patterns
