import logging

from django.apps import AppConfig

logger = logging.getLogger(__name__)


class PricemonConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'pricemon'

    def ready(self):
        import pricemon.signals  # noqa: F401
        try:
            from pricemon.tasks import schedule_watcher
            from pricemon.models import PriceWatcher
            for watcher in PriceWatcher.objects.filter(enabled=True):
                schedule_watcher(watcher)
                logger.info(f'Scheduled pricemon watcher: {watcher.name}')
        except Exception as exc:
            logger.warning(f'Could not schedule pricemon watchers on startup: {exc}')
