# target_simulator/core/communicator_interface.py
"""
Defines the interface for all communication handlers.
"""

from abc import ABC, abstractmethod
from typing import Dict, Any, List

from .models import Scenario
from target_simulator.core.models import Scenario


class CommunicatorInterface(ABC):
    """
    Abstract Base Class for communication strategies (e.g., Serial, TFTP).
    """

    @abstractmethod
    def connect(self, config: Dict[str, Any]) -> bool:
        """Establishes a connection using the provided configuration."""
        pass

    @abstractmethod
    def disconnect(self) -> None:
        """Closes the connection."""
        pass

    @property
    @abstractmethod
    def is_open(self) -> bool:
        """Returns True if the connection is active."""
        pass

    @abstractmethod
    def send_scenario(self, scenario: Scenario) -> bool:
        """Sends an entire scenario to the target device."""
        pass

    @staticmethod
    @abstractmethod
    def test_connection(config: Dict[str, Any]) -> bool:
        """
        Tests the connection with the given config without keeping it open.

        This is a static method as it should not rely on an existing instance.
        """
        pass

    @staticmethod
    @abstractmethod
    def list_available_ports() -> List[str]:
        """
        Lists available resources for this communication type.
        For Serial, this returns COM ports. For TFTP, it can return an empty list.
        """
        pass
