"""
ZIA API server entry point.

Run with:
    python -m zia.api.server
    zia serve --host 0.0.0.0 --port 8000
"""

from __future__ import annotations

import os


def run(host: str = "0.0.0.0", port: int = 8000, reload: bool = False) -> None:
    try:
        import uvicorn
    except ImportError:
        raise RuntimeError(
            "uvicorn is required to run the ZIA API server. "
            "Install it with: pip install 'zia[api]'"
        )

    uvicorn.run(
        "zia.api.main:app",
        host=host,
        port=port,
        reload=reload,
        log_level="info",
    )


if __name__ == "__main__":
    run(
        host=os.environ.get("ZIA_HOST", "0.0.0.0"),
        port=int(os.environ.get("ZIA_PORT", "8000")),
        reload=os.environ.get("ZIA_RELOAD", "").lower() in ("1", "true"),
    )
