from __future__ import annotations

from typing import Any

from niannian.bridge.pairing import PairingService


class BridgeWebSocket:
    """WebSocket 处理骨架 — 完整 WS 在 bridge-client 连接后扩展。"""

    def __init__(self, pairing: PairingService) -> None:
        self._pairing = pairing
        self._sessions: dict[str, dict[str, Any]] = {}

    async def handle_message(self, device_id: str, payload: dict[str, Any]) -> dict[str, Any]:
        msg_type = payload.get("type")
        if msg_type == "ping":
            return {"type": "pong"}
        if msg_type == "chat.message":
            return {"type": "chat.deferred", "message": "use HTTP /v1/chat in MVP"}
        if msg_type == "device.request":
            return {"type": "device.deferred", "reason": "mac_relay_not_connected"}
        return {"type": "error", "message": f"unknown type: {msg_type}"}
