"""Vaultfire AgentKit — Quick Start Example

This example shows how to create an AI agent with on-chain trust
using Coinbase AgentKit + Vaultfire in under 30 lines.

Prerequisites:
  pip install coinbase-agentkit vaultfire-agentkit

Set environment variables:
  CDP_API_KEY_ID=your-key-id
  CDP_API_KEY_SECRET=your-key-secret
  CDP_WALLET_SECRET=your-wallet-secret
"""

import os

from coinbase_agentkit import (
    AgentKit,
    AgentKitConfig,
    CdpEvmWalletProvider,
    CdpEvmWalletProviderConfig,
    wallet_action_provider,
)
from vaultfire_agentkit import vaultfire_action_provider


def main():
    # 1. Set up a wallet on Base mainnet
    wallet_provider = CdpEvmWalletProvider(CdpEvmWalletProviderConfig(
        api_key_id=os.environ["CDP_API_KEY_ID"],
        api_key_secret=os.environ["CDP_API_KEY_SECRET"],
        wallet_secret=os.environ["CDP_WALLET_SECRET"],
        network_id="base-mainnet",
    ))

    # 2. Create AgentKit with Vaultfire trust actions
    agentkit = AgentKit(AgentKitConfig(
        wallet_provider=wallet_provider,
        action_providers=[
            wallet_action_provider(),
            vaultfire_action_provider(),
        ],
    ))

    # 3. Get all available actions (includes 7 Vaultfire trust actions)
    actions = agentkit.get_actions()
    print(f"Agent has {len(actions)} available actions:")
    for action in actions:
        print(f"  - {action.name}: {action.description[:80]}...")

    # 4. Register the agent on-chain
    register_action = next(a for a in actions if "register_agent" in a.name)
    result = register_action.invoke({
        "name": "quickstart-demo-agent",
        "agent_type": "autonomous",
    })
    print(f"\n{result}")

    # 5. Create an accountability bond (stake 0.001 ETH)
    bond_action = next(a for a in actions if "create_accountability_bond" in a.name)
    result = bond_action.invoke({"amount": "0.001"})
    print(f"\n{result}")

    # 6. Check own trust profile
    profile_action = next(a for a in actions if "get_trust_profile" in a.name)
    result = profile_action.invoke({
        "agent_address": wallet_provider.get_address(),
    })
    print(f"\n{result}")


if __name__ == "__main__":
    main()
