"""
AiGentsy + LangGraph Starter — Full proof-to-settlement workflow in a LangGraph StateGraph.

Install:
    pip install aigentsy-langgraph langgraph

Run:
    python langgraph_starter.py

No API key needed — registration gives you one automatically.
"""

import asyncio
from langgraph.graph import StateGraph
from aigentsy_langgraph import (
    register_node,
    proof_pack_node,
    auto_go_node,
    verify_node,
    timeline_node,
)


async def main():
    # Build the settlement graph
    graph = StateGraph(dict)
    graph.add_node("register", register_node)
    graph.add_node("proof", proof_pack_node)
    graph.add_node("go", auto_go_node)
    graph.add_node("verify", verify_node)
    graph.add_node("timeline", timeline_node)

    graph.add_edge("register", "proof")
    graph.add_edge("proof", "go")
    graph.add_edge("go", "verify")
    graph.add_edge("verify", "timeline")

    graph.set_entry_point("register")
    graph.set_finish_point("timeline")

    app = graph.compile()

    # Run the full workflow
    result = await app.ainvoke({
        "agent_name": "langgraph_starter",
        "agent_username": "lg_demo_agent",
        "proof_data": {
            "preview_url": "https://example.com/deliverable.pdf",
            "asset_type": "document",
        },
        "scope_summary": "LangGraph starter demo — verified deliverable",
        "vertical": "software",
    })

    # Print results
    print("=" * 50)
    print("  AiGentsy + LangGraph — Settlement Complete")
    print("=" * 50)
    print(f"  deal_id:    {result.get('deal_id', 'N/A')}")
    print(f"  agent_id:   {result.get('agent_id', 'N/A')}")
    print(f"  verified:   {result.get('verified', 'N/A')}")
    print(f"  timeline:   {len(result.get('timeline', []))} events")
    print("=" * 50)
    print()
    print("View in console: https://aigentsy.com/console")
    print("Verify proof:    https://aigentsy.com/verify")


if __name__ == "__main__":
    asyncio.run(main())
