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

(
    AbstractCategory,
    AbstractProduct,
    AbstractOption,
    AbstractProductClass,
    AbstractProductAttribute,
    AbstractProductAttributeValue,
) = get_classes(
    "catalogue.abstract_models",
    [
        "AbstractCategory",
        "AbstractProduct",
        "AbstractOption",
        "AbstractProductClass",
        "AbstractProductAttribute",
        "AbstractProductAttributeValue",
    ],
)

###############################################################################
# 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("catalogue", "ProductClass"):

    class ProductClass(AbstractProductClass):
        pass

    __all__.append("ProductClass")


if not is_model_registered("catalogue", "Category"):

    class Category(AbstractCategory):
        pass

    __all__.append("Category")


if not is_model_registered("catalogue", "Product"):

    class Product(AbstractProduct):
        pass

    __all__.append("Product")


if not is_model_registered("catalogue", "Option"):

    class Option(AbstractOption):
        pass

    __all__.append("Option")


if not is_model_registered("catalogue", "ProductAttribute"):

    class ProductAttribute(AbstractProductAttribute):
        pass

    __all__.append("ProductAttribute")


if not is_model_registered("catalogue", "ProductAttributeValue"):

    class ProductAttributeValue(AbstractProductAttributeValue):
        pass

    __all__.append("ProductAttributeValue")

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

__all__.extend(some)
