"""Quick WebSocket client to test the full proxy pipeline."""

import asyncio
import json
import websockets


async def main() -> None:
    uri = "ws://localhost:8000/chat"
    async with websockets.connect(uri) as ws:
        print("=== Connected ===\n")

        # 1) Press-to-talk: key_down
        print("[TX] key_down")
        await ws.send(json.dumps({"type": "hardware_event", "action": "key_down"}))
        resp = json.loads(await ws.recv())
        print(f"[RX] {resp}\n")

        # 2) Send audio frames while "holding button"
        print("[TX] binary audio (80 bytes of mock Opus)")
        await ws.send(b"\x00" * 80)

        # 3) Release button: key_up triggers STT → LLM → TTS pipeline
        print("[TX] key_up")
        await ws.send(json.dumps({"type": "hardware_event", "action": "key_up"}))

        # Collect all responses until we get binary audio back
        while True:
            msg = await ws.recv()
            if isinstance(msg, bytes):
                print(f"[RX] binary audio: {len(msg)} bytes")
                break
            else:
                data = json.loads(msg)
                print(f"[RX] {data}")

        print("\n=== Done ===")


if __name__ == "__main__":
    asyncio.run(main())
