//! Basic usage example for the Gemini SDK

use gemini_sdk::{GeminiSDK, MessageRequest, Agent};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize SDK
    let mut sdk = GeminiSDK::new()?;

    // Example 1: Simple text message
    println!("=== Example 1: Simple text message ===");
    let request = MessageRequest::text_only("Hello, how are you?");
    
    match sdk.send_message(request).await {
        Ok(response) => {
            println!("Response: {}", response.content);
        }
        Err(e) => {
            println!("Error: {}", e);
        }
    }

    // Example 2: Using an agent
    println!("\n=== Example 2: Using an agent ===");
    let agent = Agent::new(
        "helpful_assistant",
        "Helpful Assistant",
        "You are a helpful assistant that provides clear and concise answers."
    ).with_temperature(0.7);
    
    sdk.add_agent(agent);

    let request = MessageRequest::with_agent(
        "Explain quantum computing in simple terms",
        "helpful_assistant"
    );

    match sdk.send_message(request).await {
        Ok(response) => {
            println!("Agent response: {}", response.content);
        }
        Err(e) => {
            println!("Error: {}", e);
        }
    }

    // Example 3: Message with image attachment (commented out as it requires a real image file)
    /*
    println!("\n=== Example 3: Message with image attachment ===");
    let request = MessageRequest::with_attachments(
        "What do you see in this image?",
        vec![Attachment::new("./example.jpg")]
    );

    match sdk.send_message(request).await {
        Ok(response) => {
            println!("Image analysis: {}", response.content);
        }
        Err(e) => {
            println!("Error: {}", e);
        }
    }
    */

    // Example 4: Creating a specialized agent
    println!("\n=== Example 4: Creating a specialized agent ===");
    let code_agent = Agent::new(
        "code_reviewer",
        "Code Reviewer",
        r#"You are an expert code reviewer. When given code, you should:
1. Analyze the code for potential bugs or issues
2. Suggest improvements for readability and performance
3. Check for best practices and coding standards
4. Provide constructive feedback

Always be specific and provide examples when possible."#
    ).with_temperature(0.3)  // Lower temperature for more focused responses
     .with_max_tokens(4096);

    sdk.add_agent(code_agent);

    let code_example = r#"
def fibonacci(n):
    if n <= 1:
        return n
    else:
        return fibonacci(n-1) + fibonacci(n-2)

print(fibonacci(10))
"#;

    let request = MessageRequest::with_agent(
        format!("Please review this Python code:\n\n```python{}\n```", code_example),
        "code_reviewer"
    );

    match sdk.send_message(request).await {
        Ok(response) => {
            println!("Code review: {}", response.content);
        }
        Err(e) => {
            println!("Error: {}", e);
        }
    }

    // Example 5: List all agents
    println!("\n=== Example 5: List all agents ===");
    let agents = sdk.list_agents();
    for agent in agents {
        println!("Agent: {} (ID: {})", agent.name, agent.id);
        println!("  Temperature: {}", agent.temperature);
        println!("  Max tokens: {}", agent.max_tokens);
        println!("  System prompt: {}...", 
                 agent.system_prompt.chars().take(50).collect::<String>());
        println!();
    }

    Ok(())
}
