from oscar.core.loading import get_classes, is_model_registered

# pylint: disable=W0614,W0401
(
    AbstractLineAttribute,
    AbstractBillingAddress,
    AbstractShippingAddress,
    AbstractOrder,
    AbstractLine,
    AbstractSurcharge,
    AbstractCarrier,
    AbstractTracking,
) = get_classes(
    "order.abstract_models",
    [
        "AbstractLineAttribute",
        "AbstractBillingAddress",
        "AbstractShippingAddress",
        "AbstractOrder",
        "AbstractLine",
        "AbstractSurcharge",
        "AbstractCarrier",
        "AbstractTracking",
    ],
)

###############################################################################
# This is how to override an oscar app, while keeping the overriding app      #
# overridable itself.                                                         #
# The mechanism is the same as in oscar, the only think different is the way  #
# ``__all__`` is being updated with the exports of the original oscar app.    #
###############################################################################

__all__ = []

if not is_model_registered("order", "Order"):

    class Order(AbstractOrder):
        pass

    __all__.append("Order")

if not is_model_registered("order", "Line"):

    class Line(AbstractLine):
        pass

    __all__.append("Line")

if not is_model_registered("order", "LineAttribute"):

    class LineAttribute(AbstractLineAttribute):
        pass

    __all__.append("LineAttribute")

if not is_model_registered("order", "BillingAddress"):

    class BillingAddress(AbstractBillingAddress):
        pass

    __all__.append("BillingAddress")


if not is_model_registered("order", "ShippingAddress"):

    class ShippingAddress(AbstractShippingAddress):
        pass

    __all__.append("ShippingAddress")

if not is_model_registered("order", "Surcharge"):

    class Surcharge(AbstractSurcharge):
        pass

    __all__.append("Surcharge")


if not is_model_registered("order", "Carrier"):

    class Carrier(AbstractCarrier):
        pass

    __all__.append("Carrier")


if not is_model_registered("order", "Tracking"):

    class Tracking(AbstractTracking):
        pass

    __all__.append("Tracking")


# both these lines are reruired, the first one imports all objects the are not
# implemented above into the current namespace.
# the second line updates the __all__ variable of the current namespace with
# the objects from the oscar namespace.
# THIS ENSURE THAT THE SAME CAN BE DONE BY ANOTHER APP, SO THIS APP CAN BE ONCE
# MORE EXTENDED BY ANOTHER APP.
from oscar.apps.order.models import *  # noqa
from oscar.apps.order.models import __all__ as some

__all__.extend(some)
