from abc import ABC, abstractmethod


class BaseBroker(ABC):
    """Abstract base class for message brokers.

    Implementations: MQTTBroker (paho-mqtt 5.0).
    Future: CoapBroker, HttpBroker, WebSocketBroker.
    """

    def __init__(self, name, config):
        self.name = name
        self.config = config
        self._connected = False

    @abstractmethod
    def connect(self):
        """Connect to the broker."""

    @abstractmethod
    def disconnect(self):
        """Disconnect from the broker."""

    @abstractmethod
    def subscribe(self, topic, qos=1):
        """Subscribe to a topic pattern."""

    @abstractmethod
    def publish(self, topic, payload, qos=1, **kwargs):
        """Publish a message to a topic."""

    @abstractmethod
    def loop_forever(self):
        """Blocking loop that processes incoming messages."""

    @abstractmethod
    def loop_start(self):
        """Start a background thread for message processing."""

    @abstractmethod
    def loop_stop(self):
        """Stop the background processing thread."""

    @property
    def is_connected(self):
        return self._connected
