"""Example: Async IKE bridge usage.

Demonstrates using ``AsyncIKEBridge`` for non-blocking IKE operations
in async contexts (FastAPI handlers, async pipelines, etc.).

Prerequisites:
    - IKE service running at ``SDK_IKE_ENDPOINT``
    - ``ike`` package installed with async client support
"""

from __future__ import annotations

import asyncio

from sdk import SDKConfig, SDKContext
from databridge_core.sdk.core.ike_bridge import AsyncIKEBridge, async_ike_available


async def main() -> None:
    print(f"Async IKE client available: {async_ike_available()}")

    config = SDKConfig(
        enable_ike=True,
        ike_endpoint="http://localhost:8000",
        ike_tenant_id="demo",
    )

    ctx = SDKContext(config=config, user_id="async-demo@example.com")

    # Access async IKE bridge via context
    bridge = ctx.async_ike
    print(f"Async IKE bridge: {bridge}")
    print(f"  Available: {bridge.available}")

    if bridge.available:
        # P1: Knowledge Base
        entry_id = await bridge.ingest_knowledge(
            content="GL account 4100 is always Rent Expense",
            source_type="manual",
            tags=["accounting", "gl"],
        )
        print(f"  Ingested KB entry: {entry_id}")

        results = await bridge.query_knowledge("rent expense accounts")
        print(f"  Query results: {results}")

        # P4: Scoring
        score = await bridge.score(
            bandit_id="detection_FDP_001",
            item_id="finding_42",
            raw_confidence=0.87,
        )
        print(f"  Score result: {score}")

        # Clean up
        await bridge.close()
    else:
        print("  Skipping — IKE not available (install ike package)")

    ctx.close()


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