import abc
from datetime import datetime
from typing import Any, Dict


class BaseModule(abc.ABC):
    """
    Abstract Base Class that defines the mandatory interface for all PyMsc modules.
    Ensures that different communication channels follow the same logic.
    """

    def __init__(self, name: str):
        self.module_name = name
        self.is_running = False

    @abc.abstractmethod
    def initialize(self, config: Dict[str, Any]) -> bool:
        """
        Setup the communication and resources.
        :param config: Dictionary containing IP, ports, or hardware addresses.
        :return: True if initialization is successful, False otherwise.
        """
        pass

    @abc.abstractmethod
    def start_session(self) -> None:
        """
        Starts the data acquisition or simulation.
        """
        self.is_running = True

    @abc.abstractmethod
    def stop_session(self) -> None:
        """
        Stops the module and releases resources.
        """
        self.is_running = False

    @abc.abstractmethod
    def get_status(self) -> Dict[str, Any]:
        """
        Returns the health status of the module.
        :return: A dictionary with status information.
        """
        pass

    def get_system_timestamp(self) -> float:
        """
        Helper to get a uniform system timestamp for data normalization.
        :return: Current system time in seconds (float).
        """
        now = datetime.now()
        timestamp = now.timestamp()
        return timestamp