"""
Example: Using Argus to monitor Kiro AI assistant
"""

from argus import watch
import time


# Example 1: Track Kiro's code generation
@watch.agent(name="kiro-code-generator", tags=["kiro", "production"])
def generate_code(prompt: str, language: str = "python"):
    """
    Simulate Kiro generating code
    In real usage, this would call Kiro's API
    """
    # Simulate API call
    time.sleep(0.5)
    
    # Mock response
    code = f"""
def example():
    # Generated by Kiro
    print("Hello from {language}")
"""
    
    return {
        "code": code,
        "language": language,
        "tokens": 150,
        "cost": 0.0003
    }


# Example 2: Track Kiro's file operations
@watch.agent(name="kiro-file-ops", tags=["kiro", "filesystem"])
def kiro_file_operation(operation: str, file_path: str):
    """
    Track when Kiro reads/writes files
    """
    time.sleep(0.1)
    
    return {
        "operation": operation,
        "file": file_path,
        "success": True
    }


# Example 3: Track Kiro's debugging sessions
@watch.agent(name="kiro-debugger", tags=["kiro", "debug"])
def debug_code(code: str, error: str):
    """
    Track Kiro's debugging attempts
    """
    time.sleep(0.8)
    
    return {
        "fixed": True,
        "suggestion": "Add error handling",
        "confidence": 0.95
    }


# Example 4: Track Kiro's chat responses
@watch.agent(name="kiro-chat", tags=["kiro", "chat"])
def kiro_chat(user_message: str):
    """
    Track Kiro's chat interactions
    """
    time.sleep(0.3)
    
    return {
        "response": "I can help you with that!",
        "tokens": 50,
        "cost": 0.0001
    }


if __name__ == "__main__":
    print("🤖 Monitoring Kiro AI Assistant with Argus\n")
    
    # Simulate Kiro usage
    print("1. Kiro generates code...")
    result = generate_code("Create a hello world function", "python")
    print(f"   ✅ Generated {len(result['code'])} chars, cost: ${result['cost']}\n")
    
    print("2. Kiro reads a file...")
    result = kiro_file_operation("read", "app.py")
    print(f"   ✅ {result['operation']} {result['file']}\n")
    
    print("3. Kiro debugs code...")
    result = debug_code("def broken(): pass", "SyntaxError")
    print(f"   ✅ Fixed: {result['fixed']}, confidence: {result['confidence']}\n")
    
    print("4. Kiro responds to chat...")
    result = kiro_chat("How do I use decorators?")
    print(f"   ✅ Response: {result['response']}\n")
    
    # Show statistics
    print("=" * 50)
    print("📊 Kiro Usage Statistics:")
    print("=" * 50)
    
    stats = watch.stats()
    print(f"\nTotal Kiro operations: {stats['total_calls']}")
    print(f"Total cost: ${stats['total_cost']:.4f}")
    
    print("\n🤖 Per Agent:")
    for agent in watch.list_agents():
        if "kiro" in agent['name']:
            print(f"\n  📋 {agent['name']}")
            print(f"     Calls: {agent['total_calls']}")
            print(f"     Avg time: {agent['avg_duration_ms']:.0f}ms")
            print(f"     Cost: ${agent['total_cost']:.4f}")
    
    print("\n" + "=" * 50)
    print("🎯 View dashboard: argus dashboard")
    print("=" * 50)
