"""Pharos Atlas x402 buyer example — Base mainnet USDC.

Install: pip install x402 eth-account httpx
Keep EVM_PRIVATE_KEY in a secrets manager and fund that wallet with Base USDC.
"""
import asyncio
import os

from eth_account import Account
from x402 import x402Client
from x402.http.clients import x402HttpxClient
from x402.mechanisms.evm import EthAccountSigner
from x402.mechanisms.evm.exact.register import register_exact_evm_client


async def main() -> None:
    private_key = os.environ["EVM_PRIVATE_KEY"]
    client = x402Client()
    register_exact_evm_client(client, EthAccountSigner(Account.from_key(private_key)))

    async with x402HttpxClient(client) as http:
        response = await http.post(
            "https://pharosatlas.com/api/answer",
            json={
                "question": "Does security film make ordinary glass bulletproof?",
                "intent": "verify_claim",
                "language": "en",
            },
        )
        await response.aread()
        response.raise_for_status()
        print(response.json())
        print("PAYMENT-RESPONSE:", response.headers.get("PAYMENT-RESPONSE"))


asyncio.run(main())
