from django.db.models.signals import post_migrate
from django.utils.translation import gettext_lazy as _

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

from ocyan.plugin.oscar_checkout.shared.appconfig import CheckoutAppConfig


class CheckoutConfig(CheckoutAppConfig, OscarConfig):
    label = "checkout"
    name = "ocyan.plugin.oscar_checkout.checkout"
    namespace = "checkout"
    verbose_name = _("Checkout")

    def ready(self):
        self.index_view = get_class("checkout.views", "IndexView")
        self.cancel_view = get_class("checkout.views", "CancelView")
        self.thankyou_view = get_class("checkout.views", "ThankYouView")
        self.thankyou_from_link_view = get_class(
            "checkout.views", "ThankYouFromLinkView"
        )
        self.order_not_found_view = get_class("checkout.views", "OrderNotFoundView")
        self.try_again_view = get_class("checkout.views", "TryAgainView")
        self.try_again_from_link_view = get_class(
            "checkout.views", "TryAgainFromLinkView"
        )

        from ocyan.plugin.oscar_checkout.checkout.signal_handlers import (
            setup_payment_methods,
        )

        post_migrate.connect(setup_payment_methods, sender=self)
