import logging

from django.apps import AppConfig
from django.conf import settings

logger = logging.getLogger(__name__)


class EPDBConfig(AppConfig):
    default_auto_field = "django.db.models.BigAutoField"
    name = "epdb"

    def ready(self):
        import epdb.signals  # noqa: F401

        model_name = getattr(settings, "EPDB_PACKAGE_MODEL", "epdb.Package")
        logger.info(f"Using Package model: {model_name}")

        from .autodiscovery import autodiscover

        autodiscover()

        if settings.PLUGINS_ENABLED:
            from bridge.contracts import Property, Classifier
            from utilities.plugin import discover_plugins

            settings.PROPERTY_PLUGINS.update(**discover_plugins(_cls=Property))
            settings.CLASSIFIER_PLUGINS.update(**discover_plugins(_cls=Classifier))
