from __future__ import annotations

from django.apps import AppConfig


class PlatformCoreConfig(AppConfig):
    """Cross-cutting generic models used by every business module.

    Owns: ``Attachment``, ``Comment``, ``Activity``, ``CustomFieldDefinition``,
    ``CustomFieldValue``, ``Tag``, ``TagAssignment``, ``Note``, ``Mention``,
    ``ReferenceNumberSequence``, ``PrintTemplate``, ``DocumentTemplate``,
    ``ExportLayout``, ``MessageTemplate``.
    Each uses a :class:`GenericForeignKey` or scoped FK so any other module can
    attach arbitrary metadata to its own entities without coupling the schemas.
    """

    name = "simorgh.apps.platform_core"
    label = "platform_core"
    default_auto_field = "django.db.models.BigAutoField"
    verbose_name = "Platform core"

    def ready(self) -> None:  # pragma: no cover — wiring
        from simorgh.apps.platform_core import events as _events
        from simorgh.apps.platform_core import permissions as _perms
        from simorgh.apps.platform_core import settings as _settings

        _perms.register_all()
        _events.register_all()
        _settings.register_all()
        self._register_notification_templates()

    def _register_notification_templates(self) -> None:  # pragma: no cover
        from simorgh.apps.notifications.templates import NotificationTemplate, register_template

        register_template(
            NotificationTemplate(
                kind="core.mention_in_comment",
                title_key="notifications.mention_in_comment.title",
                body_key="notifications.mention_in_comment.body",
                default_channels=("inbox",),
            )
        )
        register_template(
            NotificationTemplate(
                kind="core.mention_in_note",
                title_key="notifications.mention_in_note.title",
                body_key="notifications.mention_in_note.body",
                default_channels=("inbox",),
            )
        )
