"""``mgf-fed-web`` console entry — serve the federation dashboard on localhost.

Runs the read-only FastAPI app under uvicorn, bound to 127.0.0.1:8788 by default
(``--host`` / ``--port`` override). ``--version`` reports the package version and exits
(OP-01 — every federation console script answers ``--version``, and the release-smoke CI
step asserts it). Local, single-user, no auth: it only displays the spine's
``generated/`` state.
"""

from __future__ import annotations

import argparse

from . import __version__


def main(argv: list[str] | None = None) -> None:
    """Serve the dashboard (default http://127.0.0.1:8788), or report ``--version``."""
    parser = argparse.ArgumentParser(
        prog="mgf-fed-web",
        description="serve the MGF federation dashboard (read-only, localhost)",
    )
    parser.add_argument("--version", action="version", version=f"mgf-fed-web {__version__}")
    parser.add_argument("--host", default="127.0.0.1", help="bind host (default: 127.0.0.1)")
    parser.add_argument("--port", type=int, default=8788, help="bind port (default: 8788)")
    args = parser.parse_args(argv)

    import uvicorn

    from .web import create_app

    uvicorn.run(create_app(), host=args.host, port=args.port)


if __name__ == "__main__":
    main()
