# from django.apps import AppConfig


# class MyappConfig(AppConfig):
#     default_auto_field = 'django.db.models.BigAutoField'
#     name = 'myapp'
from django.apps import AppConfig


class MyappConfig(AppConfig):
    # ✅ 'yourapp' என்பதை உங்கள் actual app name-ஆக மாற்றுங்கள்
    name = 'myapp'

    def ready(self):
        """
        Server start ஆகும்போதே எல்லா face encodings-ஐயும் memory-ல் load பண்ணும்.
        இதனால் முதல் attendance request கூட fast-ஆக வரும்.
        """
        import threading

        def preload():
            try:
                # Import here to avoid circular import
                from .views import load_encoding_cache
                load_encoding_cache(force=True)
                print("[Startup] Face encoding cache preloaded ✅")
            except Exception as e:
                # DB migration run ஆகலன்னா error வரும் — safe-ஆ ignore பண்ணலாம்
                print(f"[Startup] Cache preload skipped: {e}")

        # Background thread-ல் load பண்ணும் — server startup delay இல்லாமல்
        t = threading.Thread(target=preload, daemon=True)
        t.start()