"""Shared pure advisory tool implementation; the payment guard still must be attached."""
from __future__ import annotations

import json
from typing import Any

from spendpreflight import Rules, evaluate_local


def check_selected_offer(requirement_json: str, resource_url: str, max_usd: str = "1") -> dict[str, Any]:
    """Local rule check only. No OFAC claim, network call, key or payment."""
    if len(requirement_json.encode("utf-8")) > 65536:
        raise ValueError("Payment option must fit in 64 KiB")
    value = json.loads(requirement_json)
    if not isinstance(value, dict):
        raise ValueError("Provide one selected payment option as a JSON object")
    return evaluate_local(value, resource_url, Rules(max_per_payment_usd=max_usd)).to_dict()
