#!/usr/bin/env python3
"""Convert a saved CUA trace JSON file to HTML."""

from __future__ import annotations

import argparse
import sys
from pathlib import Path

from sicss2026.html_exporter import json_file_to_html


def main() -> int:
    parser = argparse.ArgumentParser(description="Convert a CUA trace JSON file to HTML.")
    parser.add_argument("json_path", type=Path, help="Path to trace JSON")
    parser.add_argument(
        "-o",
        "--output",
        type=Path,
        help="Output HTML path (default: same name with .html)",
    )
    args = parser.parse_args()

    if not args.json_path.is_file():
        print(f"File not found: {args.json_path}", file=sys.stderr)
        return 1

    out = json_file_to_html(args.json_path, args.output)
    print(f"HTML saved: {out}")
    return 0


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