#!/usr/bin/env python3
"""
Test the new module structure that mirrors Rust's organization.
"""

# Import from submodules like Rust
from up_py.communication import SimplePublisher, UPayload
from up_py.local_transport import LocalTransport
from up_py import StaticUriProvider, UMessage

# Constants
ORIGIN_RESOURCE_ID = 0xb4c1

def console_printer(msg: UMessage) -> None:
    """Callback function to handle received messages"""
    text = msg.extract_string()
    if text:
        print(f"received event: {text}")

def main():
    print("Testing new module structure...")
    print()
    
    # Create URI provider (top-level)
    print("✓ Imported StaticUriProvider from up_py")
    uri_provider = StaticUriProvider("my-vehicle", 0xa34b, 0x01)
    
    # Create local transport (from local_transport submodule)
    print("✓ Imported LocalTransport from up_py.local_transport")
    transport = LocalTransport()
    
    # Register listener
    print("Registering listener...")
    transport.register_listener(uri_provider, ORIGIN_RESOURCE_ID, console_printer)
    
    # Create publisher (from communication submodule)
    print("✓ Imported SimplePublisher from up_py.communication")
    publisher = SimplePublisher(transport, uri_provider)
    
    # Create and publish payload (from communication submodule)
    print("✓ Imported UPayload from up_py.communication")
    payload = UPayload.from_string("Hello from restructured Python bindings!")
    publisher.publish(ORIGIN_RESOURCE_ID, payload)
    
    print()
    print("="*60)
    print("✅ Module structure test successful!")
    print()
    print("Import examples:")
    print("  from up_py.communication import SimplePublisher, UPayload")
    print("  from up_py.local_transport import LocalTransport")
    print("  from up_py import StaticUriProvider, UMessage")
    print("="*60)

if __name__ == "__main__":
    main()
