# -*- coding: utf-8 -*-
from ocyan.core.fender import config
from ocyan.plugin.oscar.plugins import OscarPluginConfig

from ocyan.plugin.oscar_shipping.plugins import ShippingPluginConfig
from ocyan.plugin.oscar_shipping.shipping.constants import SHIPPING_EVENT_SHIPPED


class ShippingFixtureConfig:
    def contribute_to_fixtures(self, fixtures):
        if config.get("shipping", "enable_charged_shipping", False):
            fixtures.add("orderanditemcharges", "shipping/orderanditemcharges")
        if config.get("shipping", "enable_weightbased_shipping", False):
            fixtures.add("weightbased", "shipping/weightbased")
        return fixtures

    def contribute_to_shipping_event_types(self, shipping_event_types):
        return shipping_event_types + [SHIPPING_EVENT_SHIPPED]


class OcyanShippingPluginConfig(
    ShippingFixtureConfig, ShippingPluginConfig, OscarPluginConfig
):
    def contribute_to_core_apps(self, core_apps):
        return core_apps + ["ocyan.plugin.oscar_shipping.shipping"]

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


class OxyanShippingPluginConfig(ShippingFixtureConfig, ShippingPluginConfig):
    def contribute_to_installed_apps(self, installed_apps):
        installed_apps.oscar.append(
            "ocyan.plugin.oscar_shipping.shipping.apps.ShippingConfig",
            replaces="oscar.apps.shipping.apps.ShippingConfig",
        )
        return installed_apps
