# -*- coding: utf-8 -*-
from django.apps import apps

from ocyan.core.plugins import OcyanPluginConfig

from .shared.entrypoint import CheckoutEntryPoint


class OcyanOscar3CheckoutPluginConfig(CheckoutEntryPoint, OcyanPluginConfig):
    def contribute_to_installed_apps(self, installed_apps):
        installed_apps.apps.extend(
            (
                "rest_framework",
                "ocyan.plugin.oscar_checkout.checkoutapi.apps.Oscar3ApiAppConfig",
            )
        )
        installed_apps.oscar.append(
            "ocyan.plugin.oscar_checkout.checkout.apps.CheckoutConfig",
            replaces="oscar.apps.checkout.apps.CheckoutConfig",
        )
        installed_apps.oscar.register_extension(
            "ocyan.plugin.oscar_checkout.oxyan_checkout_extension",
            "ocyan.plugin.oscar_checkout.checkout",
        )
        installed_apps.oscar.register_extension(
            "ocyan.plugin.oscar_checkout.payment_co_extension", "oscar.apps.payment"
        )
        installed_apps.django.append("ocyan.plugin.oscar_checkout")
        return installed_apps

    def get_api_application(self):
        return apps.get_app_config("checkoutapi")
