"""
Example: Basic usage of Supabase Session Manager with Strands Agent

Prerequisites:
1. Run migrations/001_create_session_tables.sql in your Supabase SQL Editor
2. Set environment variables:
   export SUPABASE_URL="https://your-project.supabase.co"
   export SUPABASE_KEY="your-anon-key"
"""

from dotenv import load_dotenv
from strands import Agent
from supabase_strands import SupabaseSessionManager

# Load environment variables from .env file
load_dotenv()


def main():
    # Create session manager with unique session ID
    session_id = "demo-user-123"

    # Create agent with Supabase session manager
    session_manager = SupabaseSessionManager(session_id=session_id)
    agent = Agent(session_manager=session_manager)

    # First conversation
    print("=== First Conversation ===")
    response1 = agent("Hello! My name is Alice and I love Python programming.")
    print(f"Agent: {response1}")

    # Second conversation - same session
    print("\n=== Second Conversation ===")
    response2 = agent("What's my name and what do I love?")
    print(f"Agent: {response2}")

    # Simulate new session - create new agent instance with same session_id
    print("\n=== Resuming Session (New Agent Instance) ===")
    session_manager_2 = SupabaseSessionManager(session_id=session_id)
    agent_2 = Agent(session_manager=session_manager_2)

    response3 = agent_2("Can you remind me what we discussed earlier?")
    print(f"Agent: {response3}")

    print("\n✅ All conversations persisted to Supabase!")


if __name__ == "__main__":
    main()
