from __future__ import annotations

import argparse
import os

import uvicorn

from app.ws_gateway.main import app


def main() -> None:
    parser = argparse.ArgumentParser(description="LiveKit WebSocket Gateway (PCM16 16k <-> LiveKit)")
    parser.add_argument("--port", type=int, default=8000)
    parser.add_argument("--host", type=str, default="0.0.0.0")
    parser.add_argument("--log-level", type=str, default="info")
    parser.add_argument("--reload", action="store_true")
    args = parser.parse_args()

    uvicorn.run(
        app,
        host=args.host,
        port=args.port,
        ws_ping_interval=float(os.getenv("UVICORN_WS_PING_INTERVAL_S", "20")),
        ws_ping_timeout=float(os.getenv("UVICORN_WS_PING_TIMEOUT_S", "20")),
        ws_max_size=50 * 1024 * 1024,
        log_level="info" if args.log_level is None else args.log_level,
        reload=args.reload,
    )


if __name__ == "__main__":
    main()
