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

AbstractEmail, AbstractNotification = get_classes(
    "communication.abstract_models",
    ["AbstractEmail", "AbstractNotification"],
)

###############################################################################
# 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("communication", "Email"):

    class Email(AbstractEmail):
        pass

    __all__.append("Email")


if not is_model_registered("communication", "Notification"):

    class Notification(AbstractNotification):
        pass

    __all__.append("Notification")

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

__all__.extend(some)
