#!/usr/bin/env python3
"""Report PixelRAG VLM route/model readiness."""

from __future__ import annotations

import argparse
import json
import sys
from pathlib import Path


ROOT = Path(__file__).resolve().parents[2]
if str(ROOT) not in sys.path:
    sys.path.insert(0, str(ROOT))

from services.pixelrag_vlm_route_readiness_service import (  # noqa: E402
    build_pixelrag_vlm_route_readiness,
)


def main() -> int:
    parser = argparse.ArgumentParser(
        description="讀回 PixelRAG VLM approved Ollama route / model readiness。"
    )
    parser.add_argument("--model", help="要檢查的 configured VLM model。")
    parser.add_argument(
        "--timeout",
        type=int,
        default=3,
        help="/api/tags probe timeout 秒數。",
    )
    parser.add_argument(
        "--include-models",
        action="store_true",
        help="輸出每個 host 的 model list。",
    )
    parser.add_argument(
        "--probe-generate",
        action="store_true",
        help="執行極小 /api/generate preflight；預設不呼叫模型。",
    )
    parser.add_argument(
        "--probe-timeout",
        type=int,
        default=8,
        help="/api/generate preflight timeout 秒數。",
    )
    args = parser.parse_args()

    payload = build_pixelrag_vlm_route_readiness(
        model=args.model,
        timeout_seconds=args.timeout,
        include_models=args.include_models,
        probe_generate=args.probe_generate,
        probe_timeout_seconds=args.probe_timeout,
    )
    print(json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True))
    return 0 if payload.get("success") else 1


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