# Path: mqueue/signals.py
# def mmessage_update(sender, instance, created, **kwargs):  # type: ignore
#     if created is False:
#         # try to get the user
#         user = get_user(instance)
#         if "name" not in kwargs.keys():
#             # try to get the object name
#             obj_name = get_object_name(instance, user)  # type: ignore
#         else:
#             obj_name: str = kwargs("name")  # type: ignore
#         # try to get the admin url
#         admin_url = get_admin_url(instance)
#         event_str = " edited"
#         has_event_method = getattr(instance, "event", None)
#         event_class: str = instance.__class__.__name__ + event_str
#         # create event
#         evt = MEvent.objects.create(
#             model=instance.__class__,
#             name=obj_name,
#             obj_pk=instance.pk,
#             user=user,
#             url=get_url(instance),
#             admin_url=admin_url,
#             event_class=event_class,
#             commit=not has_event_method,
#         )
#         if has_event_method:
#             evt: MEvent = instance.event(evt, "update")
#             evt.save()
#     return
# 
# def mmessage_delete(sender, instance, **kwargs):  # type: ignore
#     # try to get the user
#     user = get_user(instance)
#     # try to get the object name
#     obj_name = get_object_name(instance, user)  # type: ignore
#     event_class: str = instance.__class__.__name__ + " deleted"
#     has_event_method = getattr(instance, "event", None)
#     # create event
#     evt = MEvent.objects.create(
#         model=instance.__class__,
#         name=obj_name,
#         obj_pk=instance.pk,
#         user=user,
#         event_class=event_class,
#         commit=not has_event_method,
#     )
#     if has_event_method:
#         evt: MEvent = instance.event(evt, "delete")
#         evt.save()
#     return
# 
# def mmessage_create(sender, instance, created, **kwargs):  # type: ignore
#     if created is True:
#         # try to get the user
#         user = get_user(instance)
#         # try to get the object name
#         obj_name = get_object_name(instance, user)  # type: ignore
#         # try to get the admin url
#         admin_url = get_admin_url(instance)
#         event_class: str = instance.__class__.__name__ + " created"
#         has_event_method = getattr(instance, "event", None)
#         # create event
#         evt = MEvent.objects.create(
#             model=instance.__class__,
#             name=obj_name,
#             obj_pk=instance.pk,
#             user=user,
#             url=get_url(instance),
#             admin_url=admin_url,
#             event_class=event_class,
#             commit=not has_event_method,
#         )
#         if has_event_method:
#             evt: MEvent = instance.event(evt, "create")
#             evt.save()
#     return


from typing import List
from django.db.models.base import Model
from django.db.models.signals import post_save, post_delete
from .signals import mmessage_update, mmessage_delete, mmessage_create


class MTracker(object):
    def register(self, model: Model, monitoring_level: List[str]):
        if "c" in monitoring_level:
            post_save.connect(mmessage_create, sender=model)

# Path: mqueue/signals.py
# def mmessage_update(sender, instance, created, **kwargs):  # type: ignore
#     if created is False:
#         # try to get the user
#         user = get_user(instance)
#         if "name" not in kwargs.keys():
#             # try to get the object name
#             obj_name = get_object_name(instance, user)  # type: ignore
#         else:
#             obj_name: str = kwargs("name")  # type: ignore
#         # try to get the admin url
#         admin_url = get_admin_url(instance)
#         event_str = " edited"
#         has_event_method = getattr(instance, "event", None)
#         event_class: str = instance.__class__.__name__ + event_str
#         # create event
#         evt = MEvent.objects.create(
#             model=instance.__class__,
#             name=obj_name,
#             obj_pk=instance.pk,
#             user=user,
#             url=get_url(instance),
#             admin_url=admin_url,
#             event_class=event_class,
#             commit=not has_event_method,
#         )
#         if has_event_method:
#             evt: MEvent = instance.event(evt, "update")
#             evt.save()
#     return
# 
# def mmessage_delete(sender, instance, **kwargs):  # type: ignore
#     # try to get the user
#     user = get_user(instance)
#     # try to get the object name
#     obj_name = get_object_name(instance, user)  # type: ignore
#     event_class: str = instance.__class__.__name__ + " deleted"
#     has_event_method = getattr(instance, "event", None)
#     # create event
#     evt = MEvent.objects.create(
#         model=instance.__class__,
#         name=obj_name,
#         obj_pk=instance.pk,
#         user=user,
#         event_class=event_class,
#         commit=not has_event_method,
#     )
#     if has_event_method:
#         evt: MEvent = instance.event(evt, "delete")
#         evt.save()
#     return
# 
# def mmessage_create(sender, instance, created, **kwargs):  # type: ignore
#     if created is True:
#         # try to get the user
#         user = get_user(instance)
#         # try to get the object name
#         obj_name = get_object_name(instance, user)  # type: ignore
#         # try to get the admin url
#         admin_url = get_admin_url(instance)
#         event_class: str = instance.__class__.__name__ + " created"
#         has_event_method = getattr(instance, "event", None)
#         # create event
#         evt = MEvent.objects.create(
#             model=instance.__class__,
#             name=obj_name,
#             obj_pk=instance.pk,
#             user=user,
#             url=get_url(instance),
#             admin_url=admin_url,
#             event_class=event_class,
#             commit=not has_event_method,
#         )
#         if has_event_method:
#             evt: MEvent = instance.event(evt, "create")
#             evt.save()
#     return


# Path: mqueue/tracking.py
from typing import List
from django.db.models.base import Model
from django.db.models.signals import post_save, post_delete
from .signals import mmessage_update, mmessage_delete, mmessage_create



class MTracker(object):
    def register(self, model: Model, monitoring_level: List[str]):
        if "c" in monitoring_level:
            post_save.connect(mmessage_create, sender=model)

        if "u" in monitoring_level: