#!/usr/bin/env python3
"""
Test script for the new LLM-based persona module.
"""

import sys
import os
from datetime import datetime

# Add the project root to the Python path
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from src.utils.db import get_db_session
from src.marketing.apps.persona.llm_service import AzureLLMPersonaService


def test_persona_generation():
    """Test the new persona generation system."""
    print("🧪 Testing New LLM-Based Persona Module")
    print("=" * 50)
    
    # Test parameters
    store_id = 35
    branch_id = None
    
    print(f"📊 Testing persona generation for store {store_id}")
    print(f"🌿 Branch ID: {branch_id}")
    print()
    
    try:
        # Get database session
        db = get_db_session()
        
        # Initialize service
        service = AzureLLMPersonaService()
        
        # Generate persona
        print("🔄 Generating persona using Azure LLM...")
        result = service.generate_persona_for_store(db, store_id, branch_id)
        
        # Display results
        print("\n📋 Results:")
        print(f"✅ Success: {result.success}")
        print(f"💬 Message: {result.message}")
        
        if result.success and result.data:
            print(f"\n🎯 Persona Data:")
            print(f"   🏭 Industry: {result.data.industry}")
            print(f"   👥 Audience Type: {result.data.audience_type}")
            print(f"   🗣️ Brand Voice: {result.data.brand_voice}")
            print(f"   📝 Content Style: {result.data.content_style}")
            print(f"   📊 Confidence Score: {result.data.confidence_score}")
            print(f"   📅 Last Analyzed: {result.data.last_analyzed}")
            
            if result.analysis_metadata:
                print(f"\n🤖 LLM Analysis Metadata:")
                print(f"   📝 Analysis Text: {result.analysis_metadata.get('analysis_text', 'N/A')[:100]}...")
                print(f"   🎯 Persona Data: {result.analysis_metadata.get('persona_data', 'N/A')}")
        
        else:
            print(f"❌ Error: {result.message}")
        
        print("\n" + "=" * 50)
        print("✅ Test completed!")
        
    except Exception as e:
        print(f"\n❌ Error during testing: {str(e)}")
        import traceback
        traceback.print_exc()
    
    finally:
        if 'db' in locals():
            db.close()
            print("🔒 Database session closed")


if __name__ == "__main__":
    print("🚀 New LLM Persona Module Test")
    print("=" * 50)
    
    test_persona_generation()
    
    print("\n🎉 All tests completed!")
