"""Tests for VKPClient initialization and configuration."""

import pytest

from vkp.client import VKPClient
from vkp.delegation import DelegationManager
from vkp.keyvault import KeyVaultManager
from vkp.session import SessionKeyManager


def test_client_creation_valid_network():
    """Test client creates successfully with a valid network."""
    # Uses a mock RPC — won't connect but tests initialization
    client = VKPClient(
        rpc_url="http://localhost:8545",
        network_id="base-mainnet",
    )
    assert client.network_id == "base-mainnet"


def test_client_creation_invalid_network():
    """Test client rejects unsupported networks."""
    with pytest.raises(ValueError, match="Unsupported network"):
        VKPClient(
            rpc_url="http://localhost:8545",
            network_id="ethereum-mainnet",
        )


def test_client_has_all_managers():
    """Test client exposes keyvault, sessions, and delegations."""
    client = VKPClient(
        rpc_url="http://localhost:8545",
        network_id="base-mainnet",
    )
    assert isinstance(client.keyvault, KeyVaultManager)
    assert isinstance(client.sessions, SessionKeyManager)
    assert isinstance(client.delegations, DelegationManager)


def test_client_with_contract_addresses():
    """Test client accepts contract addresses."""
    client = VKPClient(
        rpc_url="http://localhost:8545",
        network_id="base-mainnet",
        factory_address="0x1234567890123456789012345678901234567890",
        session_manager_address="0x2345678901234567890123456789012345678901",
        delegation_registry_address="0x3456789012345678901234567890123456789012",
    )
    assert client.keyvault._factory_address == "0x1234567890123456789012345678901234567890"
    assert client.sessions._manager_address == "0x2345678901234567890123456789012345678901"
    assert client.delegations._registry_address == "0x3456789012345678901234567890123456789012"


def test_all_supported_networks():
    """Test all four networks are accepted."""
    for network in ["base-mainnet", "arbitrum-mainnet", "polygon-mainnet", "avalanche-mainnet"]:
        client = VKPClient(
            rpc_url="http://localhost:8545",
            network_id=network,
        )
        assert client.network_id == network
