#!/usr/bin/env python3
from __future__ import annotations

import argparse

import uvicorn

from argus.service.app import create_app
from argus.service.config import V2Config


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--config", required=True, help="Path to MVP config YAML (ray:/service:)")
    args = parser.parse_args()

    # Load app and read v2.api host/port from config.
    import yaml

    with open(args.config, "r", encoding="utf-8") as f:
        root = yaml.safe_load(f) or {}
    if not isinstance(root, dict):
        raise SystemExit("config yaml must be a mapping")
    v2 = V2Config.from_root_dict(root)

    app = create_app(args.config)
    uvicorn.run(app, host=v2.api.host, port=v2.api.port, log_level="info")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
