#!/usr/bin/env python3
"""Report PixelRAG platform probe readiness from barrier receipts."""

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_platform_probe_service import (  # noqa: E402
    build_pixelrag_platform_probe_readiness,
)


def main() -> int:
    parser = argparse.ArgumentParser(
        description="輸出 PixelRAG platform probe readiness 的機器可讀讀回。"
    )
    parser.add_argument(
        "--artifact-root",
        help="PixelRAG visual evidence artifact root；預設使用 production/container 設定。",
    )
    parser.add_argument(
        "--vlm-receipt-root",
        help="PixelRAG VLM replay receipt root；預設使用 production/container 設定。",
    )
    parser.add_argument(
        "--platform",
        action="append",
        dest="platforms",
        help="限制平台，可重複指定，例如 --platform shopee_tw --platform coupang_tw。",
    )
    parser.add_argument(
        "--max-age-hours",
        type=int,
        default=168,
        help="receipt 最大新鮮度小時數。",
    )
    parser.add_argument(
        "--limit",
        type=int,
        default=50,
        help="最多輸出 probe candidate 數。",
    )
    args = parser.parse_args()

    payload = build_pixelrag_platform_probe_readiness(
        artifact_root=args.artifact_root,
        vlm_receipt_root=args.vlm_receipt_root,
        platform=tuple(args.platforms or ()),
        max_age_hours=args.max_age_hours,
        limit=args.limit,
    )
    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())
