from typing import Any, Dict, Optional
from fastapi import WebSocket
from .websocket_manager import WebSocketManager

async def emit(event: str, data: Any, namespace: str = '/', room: str = None):
    """Émet un événement WebSocket"""
    await WebSocketManager().emit(event, data, namespace, room)

async def broadcast(event: str, data: Any, namespace: str = None):
    """Diffuse un événement à tous les clients"""
    await WebSocketManager().broadcast(event, data, namespace)

def join_room(room: str, websocket: WebSocket, namespace: str = '/'):
    """Ajoute un client à une room"""
    WebSocketManager().join_room(room, websocket, namespace)

def leave_room(room: str, websocket: WebSocket, namespace: str = '/'):
    """Retire un client d'une room"""
    WebSocketManager().leave_room(room, websocket, namespace)

def get_connected_clients(namespace: str = '/') -> list:
    """Retourne les clients connectés"""
    return WebSocketManager().get_connected_clients(namespace)

def get_rooms() -> Dict[str, list]:
    """Retourne toutes les rooms"""
    return WebSocketManager().get_rooms()

def get_namespaces() -> list:
    """Retourne tous les namespaces"""
    return WebSocketManager().get_namespaces()