"""
ModelRegistry — lazy-loads the single content classifier per worker.
"""
import logging
from functools import lru_cache

from app.config import settings
from app.services.vision.base import ContentClassifier

logger = logging.getLogger(__name__)


class ModelRegistry:
    def __init__(self):
        self._vision = settings.vision

    @lru_cache(maxsize=1)
    def get_classifier(self) -> ContentClassifier:
        logger.info("Loading content classifier (backend=%s)", self._vision.backend)
        from app.services.vision.classify import CLIPContentClassifier
        return CLIPContentClassifier(self._vision)

    def warmup(self):
        logger.info("Warming up vision classifier...")
        self.get_classifier()
        logger.info("Vision warmup complete")


registry = ModelRegistry()
