"""LangChain Integration Demo — how to secure a LangChain agent with one line."""

import asyncio
from langchain_core.tools import tool
from interceptor import Interceptor, Mode
from interceptor.integrations.langchain import InterceptedTool

# 1. Define your LangChain tools normally
@tool
def get_weather(location: str):
    """Get the current weather in a given location."""
    return f"It's sunny in {location}."

@tool
def delete_file(path: str):
    """Delete a local file permanently."""
    return f"File {path} deleted."

async def main():
    # 2. Setup Interceptor
    guard = Interceptor(mode=Mode.STRICT)
    print("\n[bold green]Interceptor initialized in STRICT mode.[/]\n")

    # 3. Secure your tools in ONE line
    tools = [get_weather, delete_file]
    safe_tools = [InterceptedTool(tool=t, guard=guard) for t in tools]

    # --- Scenario 1: Safe call ---
    print("--- Calling get_weather ---")
    res1 = await safe_tools[0].arun({"location": "San Francisco"})
    print(f"Tool Output: {res1}\n")

    # --- Scenario 2: Blocked call ---
    print("--- Calling delete_file ---")
    res2 = await safe_tools[1].arun({"path": "secret.txt"})
    print(f"Tool Output: {res2}\n")

    # 4. Show the session report
    print("\n[bold magenta]Final Session Report:[/]")
    guard.print_report()

if __name__ == "__main__":
    from rich import print
    asyncio.run(main())
