"""
Test 1: Send Email

Demonstrates creating an inbox and sending an email.
"""

import os
import sys
sys.path.insert(0, ".")

from agent_email import AgentEmailTool

# Set API key (use env var or set directly)
os.environ["AGENTMAIL_API_KEY"] = "your-api-key-here"

def test_send_email():
    """Test sending an email"""
    
    # Initialize tool
    tool = AgentEmailTool(agent_id="sofiia-test")
    
    # Create inbox (or use existing)
    print("Creating inbox...")
    inbox = tool.create_inbox(
        username="sofiia-test",
        display_name="Sofiia Test Agent"
    )
    print(f"Inbox created: {inbox['email_address']}")
    
    # Send email
    print("\nSending email...")
    result = tool.send(
        to=["recipient@example.com"],
        subject="Test from Sofiia Agent",
        body="""Hello!

This is a test email sent from Sofiia Agent via AgentMail.

Best regards,
Sofiia""",
        html="""<html>
<body>
<p>Hello!</p>
<p>This is a test email sent from <strong>Sofiia Agent</strong> via AgentMail.</p>
<p>Best regards,<br>Sofiia</p>
</body>
</html>"""
    )
    
    print(f"Email sent: {result['message_id']}")
    print(f"Status: {result['status']}")
    
    return result


if __name__ == "__main__":
    try:
        test_send_email()
    except Exception as e:
        print(f"Error: {e}")
