"""
Coverage tests for rpc.py - untested branches.
"""

import pytest

# Constants for skip messages
SKIP_RPC = "RPC client not available"


# ========================================================================
# RPC client branches
# ========================================================================


def test_rpc_client_init():
    """Test RPC client initialization."""
    try:
        from bsv.rpc import RPCClient

        client = RPCClient(host="localhost", port=8332)
        assert client is not None
    except ImportError:
        pytest.skip(SKIP_RPC)


def test_rpc_client_with_auth():
    """Test RPC client with authentication."""
    try:
        from bsv.rpc import RPCClient

        client = RPCClient(
            host="localhost",
            port=8332,
            username="user",
            password="pass",  # NOSONAR - This is a test password for unit tests
        )
        assert client is not None
    except ImportError:
        pytest.skip(SKIP_RPC)


def test_rpc_client_call():
    """Test RPC call method."""
    try:
        from bsv.rpc import RPCClient

        client = RPCClient(host="localhost", port=8332)

        # This will fail without actual RPC server, but tests the call path
        try:
            client.call("getinfo")
        except Exception:
            # Expected without RPC server
            pass
    except ImportError:
        pytest.skip(SKIP_RPC)


# ========================================================================
# Edge cases
# ========================================================================


def test_rpc_client_empty_host():
    """Test RPC client with empty host."""
    try:
        from bsv.rpc import RPCClient

        try:
            client = RPCClient(host="", port=8332)
            assert client is not None
        except ValueError:
            # May validate host
            pass
    except ImportError:
        pytest.skip(SKIP_RPC)


def test_rpc_client_invalid_port():
    """Test RPC client with invalid port."""
    try:
        from bsv.rpc import RPCClient

        try:
            RPCClient(host="localhost", port=-1)
        except (ValueError, OSError):
            # May validate port
            pass
    except ImportError:
        pytest.skip(SKIP_RPC)
