"""Interface for {{ module_name }}.

This module provides the hardware interface for communicating with
the {{ module_name }} device. The interface is independent of MADSci
and can be used directly in notebooks or scripts.

Generated by: madsci new module --template module/basic
Template version: {{ template_version }}
"""

import logging
from typing import Any

logger = logging.getLogger(__name__)


class {{ module_name | pascal_case }}Interface:
    """Interface for communicating with the {{ module_name }} device.

    This class encapsulates all hardware communication logic.
    It can be used independently of MADSci in notebooks or scripts.

    Example:
        >>> interface = {{ module_name | pascal_case }}Interface()
        >>> interface.connect()
        >>> result = interface.do_something("Hello")
        >>> interface.disconnect()
    """

    def __init__(self, **kwargs: Any) -> None:
        """Initialize the interface.

        Args:
            **kwargs: Configuration options for the interface.
        """
        self._connected = False
        self._config = kwargs

    @property
    def is_connected(self) -> bool:
        """Check if the interface is connected."""
        return self._connected

    def connect(self) -> None:
        """Establish connection to the device.

        Raises:
            ConnectionError: If connection fails.
        """
        # TODO: Implement actual connection logic
        # Example:
        # self._connection = DeviceDriver.connect(self._config.get("address"))

        logger.info("Connecting to {{ module_name }} device...")
        self._connected = True
        logger.info("Connected to {{ module_name }} device")

    def disconnect(self) -> None:
        """Close connection to the device."""
        if self._connected:
            # TODO: Implement actual disconnection logic
            # Example:
            # self._connection.close()

            logger.info("Disconnecting from {{ module_name }} device...")
            self._connected = False
            logger.info("Disconnected from {{ module_name }} device")

    def do_something(self, message: str) -> str:
        """Perform an example operation.

        This is a placeholder method. Replace with your actual device operations.

        Args:
            message: An example input parameter.

        Returns:
            A result string from the operation.

        Raises:
            RuntimeError: If not connected to the device.
        """
        if not self._connected:
            raise RuntimeError("Not connected to device. Call connect() first.")

        # TODO: Implement actual device operation
        # Example:
        # response = self._connection.send_command(message)
        # return response

        logger.info(f"Executing operation with message: {message}")
        return f"Processed: {message}"
