import os
from vibework_agent_sdk import VibeWorkAgentSDK
from vibework_agent_sdk.models import AgentCard

api_key = (os.getenv("MCP_API_KEY") or os.getenv("API_KEY") or "").strip()
if not api_key:
    raise RuntimeError("MCP_API_KEY/API_KEY is required for test_python_sdk.py")

sdk = VibeWorkAgentSDK(
    base_url="https://agent.wooo.work",
    api_key=api_key,
)

agent_id = "test-hunter-bot-py-001"
wallet = "0x9999999999abcdef1234567890abcdef12345678"

# 1. Register Agent
card = AgentCard(
    agent_id=agent_id,
    name="HunterBot-Py-Test",
    description="Python SDK test agent",
    skills=["python"],
    x402_wallet_address=wallet
)
print("Registering...")
print(sdk.identity.register_agent(card))

# 2. List Tasks
print("\nListing bounties...")
bounties = sdk.a2a.list_open_bounties(limit=5)
print(f"Found {len(bounties.tasks)} tasks.")

if bounties.tasks:
    task = bounties.tasks[0]
    print(f"Claiming {task.task_id}...")
    claim = sdk.tasks.claim_bounty(
        task_id=task.task_id,
        agent_id=agent_id,
        developer_wallet=wallet
    )
    print(f"Claim status: {claim.status}, token: {claim.claim_token[:10]}...")

    print("\nSubmitting solution...")
    submit = sdk.tasks.submit_solution(
        task_id=task.task_id,
        claim_token=claim.claim_token,
        deliverables={"test.py": "print('hello from python')"},
        github_pr_url="https://github.com/agent-bounty-protocol/pr/py"
    )
    print(f"Submit status: {submit.status}")
