# pylint: disable=W0614,W0401
from oscar.core.loading import get_classes, is_model_registered

(
    AbstractOrderAndItemCharges,
    AbstractWeightBased,
    AbstractWeightBand,
    AbstractProductBased,
) = get_classes(
    "shipping.abstract_models",
    [
        "AbstractOrderAndItemCharges",
        "AbstractWeightBased",
        "AbstractWeightBand",
        "AbstractProductBased",
    ],
)


###############################################################################
# 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("shipping", "OrderAndItemCharges"):

    class OrderAndItemCharges(AbstractOrderAndItemCharges):
        pass

    __all__.append("OrderAndItemCharges")


if not is_model_registered("shipping", "WeightBased"):

    class WeightBased(AbstractWeightBased):
        pass

    __all__.append("WeightBased")


if not is_model_registered("shipping", "WeightBand"):

    class WeightBand(AbstractWeightBand):
        pass

    __all__.append("WeightBand")

if not is_model_registered("shipping", "ProductBased"):

    class ProductBased(AbstractProductBased):
        pass

    __all__.append("ProductBased")

# 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.shipping.models import *  # noqa
from oscar.apps.shipping.models import __all__ as some

__all__.extend(some)
