from oscar.core.loading import get_model

from ocyan.core.plugins import OcyanPluginConfig, get_plugins
from ocyan.core.utils import unique_everseen


class ShippingPluginConfig(OcyanPluginConfig):
    def contribute_to_shipping_event_types(self, shipping_event_types):
        return shipping_event_types


def get_shipping_event_types():
    Carrier = get_model("order", "Carrier")
    plugins = get_plugins(cls=ShippingPluginConfig)
    shipping_event_types = plugins.pipe("contribute_to_shipping_event_types", [])
    carrier_shipping_event_types = Carrier.objects.all().values_list("code", flat=True)

    return list(
        unique_everseen(shipping_event_types + list(carrier_shipping_event_types))
    )
