from __future__ import annotations

from django.db.models.signals import post_save
from django.dispatch import receiver

from .models import WeighLine
from .services.carbon import create_event_for_line


@receiver(post_save, sender=WeighLine)
def weigh_line_saved(sender, instance: WeighLine, created: bool, **kwargs):
    try:
        create_event_for_line(instance)
    except Exception:
        # Fail silently to not block core operations
        pass

