"""Tests for {{ interface_name }} vendor SDK wrapper interface.

Generated by: madsci new comm --template comm/sdk
Template version: {{ template_version }}
"""

import pytest

from {{ interface_name }}_fake_interface import {{ interface_name | pascal_case }}FakeInterface


class Test{{ interface_name | pascal_case }}FakeInterface:
    """Test cases for the fake SDK wrapper interface."""

    @pytest.fixture
    def interface(self) -> {{ interface_name | pascal_case }}FakeInterface:
        """Create a test interface instance with zero latency."""
        return {{ interface_name | pascal_case }}FakeInterface(simulated_latency=0.0)

    def test_initial_state(self, interface: {{ interface_name | pascal_case }}FakeInterface) -> None:
        """Test that the interface starts unloaded and disconnected."""
        assert not interface.is_loaded
        assert not interface.is_connected
        assert interface.operation_count == 0
        assert interface.call_history == []

    def test_load_library(self, interface: {{ interface_name | pascal_case }}FakeInterface) -> None:
        """Test loading the SDK library."""
        interface.load_library()
        assert interface.is_loaded
        assert not interface.is_connected

    def test_connect_requires_load(self, interface: {{ interface_name | pascal_case }}FakeInterface) -> None:
        """Test that connecting requires the SDK to be loaded first."""
        with pytest.raises(RuntimeError, match="not loaded"):
            interface.connect()

    def test_connect_disconnect(self, interface: {{ interface_name | pascal_case }}FakeInterface) -> None:
        """Test connecting and disconnecting."""
        interface.load_library()
        interface.connect()
        assert interface.is_connected
        interface.disconnect()
        assert not interface.is_connected

    def test_call_function(self, interface: {{ interface_name | pascal_case }}FakeInterface) -> None:
        """Test calling a SDK function."""
        interface.set_function_response("measure", 42.0)
        interface.load_library()
        interface.connect()
        result = interface.call_function("measure", channel=1)
        assert result == 42.0
        assert interface.operation_count == 1

    def test_call_function_requires_connection(
        self, interface: {{ interface_name | pascal_case }}FakeInterface
    ) -> None:
        """Test that calling a function requires connection."""
        with pytest.raises(RuntimeError, match="Not connected"):
            interface.call_function("measure")

    def test_call_function_unconfigured_returns_none(
        self, interface: {{ interface_name | pascal_case }}FakeInterface
    ) -> None:
        """Test that calling an unconfigured function returns None."""
        interface.load_library()
        interface.connect()
        result = interface.call_function("unknown_function")
        assert result is None

    def test_call_history(self, interface: {{ interface_name | pascal_case }}FakeInterface) -> None:
        """Test that call history tracks function calls."""
        interface.load_library()
        interface.connect()
        interface.call_function("func_a", x=1)
        interface.call_function("func_b", y=2, z=3)

        history = interface.call_history
        assert len(history) == 2
        assert history[0]["function"] == "func_a"
        assert history[0]["kwargs"] == {"x": 1}
        assert history[1]["function"] == "func_b"
        assert history[1]["kwargs"] == {"y": 2, "z": 3}

    def test_get_property(self, interface: {{ interface_name | pascal_case }}FakeInterface) -> None:
        """Test getting a property from the SDK."""
        interface.load_library()
        interface.connect()
        interface.set_property("temperature", 25.0)
        value = interface.get_property("temperature")
        assert value == 25.0

    def test_get_property_requires_connection(
        self, interface: {{ interface_name | pascal_case }}FakeInterface
    ) -> None:
        """Test that getting a property requires connection."""
        with pytest.raises(RuntimeError, match="Not connected"):
            interface.get_property("temperature")

    def test_get_property_unset_returns_none(
        self, interface: {{ interface_name | pascal_case }}FakeInterface
    ) -> None:
        """Test that getting an unset property returns None."""
        interface.load_library()
        interface.connect()
        assert interface.get_property("nonexistent") is None

    def test_set_property(self, interface: {{ interface_name | pascal_case }}FakeInterface) -> None:
        """Test setting a property on the SDK."""
        interface.load_library()
        interface.connect()
        interface.set_property("mode", "auto")
        assert interface.get_property("mode") == "auto"

    def test_set_property_requires_connection(
        self, interface: {{ interface_name | pascal_case }}FakeInterface
    ) -> None:
        """Test that setting a property requires connection."""
        with pytest.raises(RuntimeError, match="Not connected"):
            interface.set_property("mode", "auto")

    def test_set_property_overwrites(self, interface: {{ interface_name | pascal_case }}FakeInterface) -> None:
        """Test that setting a property overwrites the previous value."""
        interface.load_library()
        interface.connect()
        interface.set_property("value", 1)
        interface.set_property("value", 2)
        assert interface.get_property("value") == 2

    def test_reset(self, interface: {{ interface_name | pascal_case }}FakeInterface) -> None:
        """Test that reset clears all internal state."""
        interface.load_library()
        interface.connect()
        interface.set_function_response("fn", 99)
        interface.call_function("fn")
        interface.set_property("key", "val")
        interface.reset()
        assert interface.operation_count == 0
        assert interface.call_history == []

    def test_operation_count_tracks_all_ops(
        self, interface: {{ interface_name | pascal_case }}FakeInterface
    ) -> None:
        """Test that operation count tracks calls, gets, and sets."""
        interface.load_library()
        interface.connect()
        interface.call_function("a")
        interface.get_property("b")
        interface.set_property("c", 1)
        assert interface.operation_count == 3
