# -*- coding: utf-8 -*-
from ocyan.core.plugins import OcyanPluginConfig
from ocyan.core.utils import merge_dicts
from ocyan.plugin.oscar.plugins import OscarPluginConfig


class OscarOrderConfig(OscarPluginConfig):
    def contribute_to_core_apps(self, core_apps):
        return core_apps + ["ocyan.plugin.oscar_order.order"]

    def contribute_to_installed_apps(self, installed_apps):
        installed_apps.oscar.append(
            "ocyan.plugin.oscar_order.order", replaces="oscar.apps.order"
        )
        return installed_apps


class Oscar3OrderConfig(OcyanPluginConfig):
    def contribute_to_settings(self, settings):
        return merge_dicts(
            settings,
            {
                "MIGRATION_MODULES": {
                    "order": "ocyan.plugin.oscar_order.oxyan_order_extension.migrations"
                }
            },
        )

    def contribute_to_installed_apps(self, installed_apps):
        installed_apps.oscar.append(
            "ocyan.plugin.oscar_order.order.apps.OrderConfig",
            replaces="oscar.apps.order.apps.OrderConfig",
        )
        installed_apps.oscar.register_extension(
            "ocyan.plugin.oscar_order.oxyan_order_extension",
            "ocyan.plugin.oscar_order.order",
        )
        return installed_apps
