"""Run the optional CLI against a self-contained synthetic offline dataset."""

import json
import subprocess
import sys
import tempfile
from pathlib import Path


def main() -> None:
    """Exercise an installed CLI without relying on repository fixtures or network."""
    with tempfile.TemporaryDirectory(prefix="rpkiparrot-example-") as temporary:
        source = Path(temporary) / "source.json"
        source.write_text(
            json.dumps(
                {
                    "metadata": {"generated": 1767225600, "generatedTime": "2026-01-01T00:00:00Z"},
                    "roas": [{"prefix": "192.0.2.0/24", "maxLength": 24, "asn": "AS64496"}],
                    "aspas": [],
                }
            ),
            encoding="utf-8",
        )
        completed = subprocess.run(
            [
                sys.executable,
                "-I",
                "-m",
                "rpkiparrot",
                "--json-file",
                str(source),
                "--max-age",
                "3600",
                "--at",
                "2026-01-01T00:00:00Z",
                "--format",
                "json",
                "validate",
                "origin",
                "192.0.2.0/24",
                "64496",
            ],
            check=True,
            capture_output=True,
            text=True,
        )
        assert json.loads(completed.stdout)["data"]["status"] == "valid"
        assert completed.stderr == ""
        print(completed.stdout, end="")


if __name__ == "__main__":
    main()
