"""
Observations signals - Signal handlers for observation events.
"""
import logging

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

from .models import Observation, ObservationStatusLog

logger = logging.getLogger(__name__)


@receiver(post_save, sender=Observation)
def observation_post_save(sender, instance, created, **kwargs):
    """
    Handle post-save events for observations.
    
    - Log creation events
    - Could trigger additional notifications or integrations
    """
    if created:
        logger.info(
            f"New observation created: {instance.tracking_code} "
            f"(severity: {instance.severity}, anonymous: {instance.is_anonymous})"
        )


@receiver(post_save, sender=ObservationStatusLog)
def status_log_post_save(sender, instance, created, **kwargs):
    """
    Handle post-save events for status logs.
    
    - Log status changes
    """
    if created:
        logger.info(
            f"Observation {instance.observation.tracking_code} status changed: "
            f"{instance.from_status} -> {instance.to_status}"
        )
