"""Defines the contract for observable components within the safety system."""

# Copyright (c) 2025 Linus Held. All rights reserved.

from abc import ABC, abstractmethod

from .fault_type import FaultType
from .observer import SafetyObserver


class ObservableInterface(ABC):
    """Abstract interface for objects that need to be monitored by a SafetyObserver.

    It defines the mechanism for attaching observers and broadcasting calculation results.
    """

    @abstractmethod
    def attach(self, observer: SafetyObserver):
        """Registers a listener (observer) to receive notifications upon computation events.

        Args:
            observer (SafetyObserver): The SafetyObserver instance to be registered.
        """
        pass

    @abstractmethod
    def notify(
        self,
        input_ports: dict,
        spfm_in: dict[FaultType, float],
        lfm_in: dict[FaultType, float],
        spfm_out: dict[FaultType, float],
        lfm_out: dict[FaultType, float],
    ) -> dict:
        """Broadcasts the computation results and visual context to all registered observers.

        Args:
            input_ports (dict): Mapping of fault types to incoming node IDs for visualization.
            spfm_in (dict[FaultType, float]): Incoming residual/SPFM fault rates.
            lfm_in (dict[FaultType, float]): Incoming latent/LFM fault rates.
            spfm_out (dict[FaultType, float]): Transformed outgoing SPFM fault rates.
            lfm_out (dict[FaultType, float]): Transformed outgoing LFM fault rates.

        Returns:
            dict: The visual output ports generated by the observers.
        """
        pass
