"""Run the HTTP-only SDK: --url for a real service, or a deterministic mock.

Install rpkiparrot[http]. The default mock demonstrates the wire boundary
without a live validator; it is not online RPKI trust evidence.
"""

from __future__ import annotations

import argparse

import anyio
import httpx

from rpkiparrot.remote import RemoteClient


def demonstration(request: httpx.Request) -> httpx.Response:
    """A small independent response, not the service implementation."""
    if request.url.path != "/v1/validate/origin":
        return httpx.Response(404)
    identity = {"store_id": "example", "epoch": "fixed", "generation": 1}
    result = {
        "status": "valid",
        "prefix": "192.0.2.0/24",
        "asn": 64496,
        "reason_codes": ["matched_vrp"],
        "snapshot_id": identity,
        "evaluated_at": "2026-10-02T00:00:00Z",
        "mode": "offline",
        "evidence": None,
    }
    return httpx.Response(
        200,
        json={
            "schema_version": 1,
            "kind": "origin_result",
            "snapshot_id": identity,
            "evaluated_at": result["evaluated_at"],
            "mode": "offline",
            "data": result,
            "error": None,
        },
    )


async def main(url: str | None) -> None:
    """Use the same public method with test and real network transports."""
    transport = httpx.MockTransport(demonstration) if url is None else None
    async with RemoteClient(url or "https://example.invalid", transport=transport) as client:
        result = await client.validate_origin("192.0.2.0/24", 64496)
        print(result.status.value, result.snapshot_id.generation, result.mode.value)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--url", help="Explicit service root; omit for the fixed mock")
    parser.add_argument("--backend", choices=("asyncio", "trio"), default="asyncio")
    args = parser.parse_args()
    anyio.run(main, args.url, backend=args.backend)
