"""Fake interface for {{ module_name }}.

This module provides a simulated interface for testing without hardware.
It implements the same methods as the real interface but operates entirely
in memory.

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

import logging
import time
from typing import Any

logger = logging.getLogger(__name__)


class {{ module_name | pascal_case }}FakeInterface:
    """Fake interface for testing {{ module_name }} without hardware.

    This class simulates device behavior for:
    - Development without physical hardware
    - Automated testing in CI/CD
    - Demo and training purposes
    - Debugging workflow logic

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

    def __init__(
        self,
        simulated_latency: float = 0.1,
        **kwargs: Any,
    ) -> None:
        """Initialize the fake interface.

        Args:
            simulated_latency: Simulated operation time in seconds.
            **kwargs: Additional configuration (ignored in fake mode).
        """
        self._connected = False
        self._simulated_latency = simulated_latency
        self._operation_count = 0
        self._state: dict[str, Any] = {}

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

    @property
    def operation_count(self) -> int:
        """Get the number of operations performed."""
        return self._operation_count

    def connect(self) -> None:
        """Simulate establishing connection to the device."""
        logger.info("[FAKE] Connecting to simulated {{ module_name }} device...")
        time.sleep(self._simulated_latency)
        self._connected = True
        self._state["connected_at"] = time.time()
        logger.info("[FAKE] Connected to simulated {{ module_name }} device")

    def disconnect(self) -> None:
        """Simulate closing connection to the device."""
        if self._connected:
            logger.info("[FAKE] Disconnecting from simulated {{ module_name }} device...")
            self._connected = False
            self._state["disconnected_at"] = time.time()
            logger.info("[FAKE] Disconnected from simulated {{ module_name }} device")

    def do_something(self, message: str) -> str:
        """Simulate performing an operation.

        Args:
            message: An example input parameter.

        Returns:
            A simulated result string.

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

        # Simulate operation latency
        time.sleep(self._simulated_latency)

        self._operation_count += 1
        self._state["last_message"] = message
        self._state["last_operation_time"] = time.time()

        logger.info(f"[FAKE] Simulated operation with message: {message}")
        return f"[FAKE] Processed: {message} (operation #{self._operation_count})"

    def get_state(self) -> dict[str, Any]:
        """Get the current internal state (useful for testing).

        Returns:
            Dictionary of internal state.
        """
        return {
            "connected": self._connected,
            "operation_count": self._operation_count,
            **self._state,
        }

    def reset_state(self) -> None:
        """Reset internal state (useful for testing)."""
        self._operation_count = 0
        self._state = {}
