#!/usr/bin/env python3
"""
Test Lia Mode B - Smart Template-Led WhatsApp Assistant
Demonstrates how Lia adapts templates based on customer context.
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from android_handler import load_lia_system_prompt

def test_mode_b_scenarios():
    """
    Test Mode B behavior with different scenarios.
    This demonstrates the expected behavior - actual OpenAI responses will vary.
    """
    
    # Load the Mode B system prompt
    prompt = load_lia_system_prompt()
    
    print("=" * 80)
    print("LIA MODE B - SYSTEM PROMPT TEST")
    print("=" * 80)
    print(f"\n✅ System prompt loaded: {len(prompt)} characters")
    print(f"✅ Contains Mode B rules: {'MODE B' in prompt}")
    print(f"✅ Contains all 8 templates: {all(t in prompt for t in ['renewal_18_new', 'renewal_18_used', 'renewal_12_generic', 'renewal_9_generic', 'renewal_6_generic', 'renewal_3_generic', 'renewal_3_price', 'campaign_bespoke_generic'])}")
    
    print("\n" + "=" * 80)
    print("TEST SCENARIOS")
    print("=" * 80)
    
    # Scenario 1: Price objection with deferral
    print("\n📝 SCENARIO 1: Price objection + house move deferral")
    print("-" * 80)
    print("Customer: Jonathan Jordan")
    print("Vehicle: Audi Q5 DIESEL ESTATE (FY72UBT)")
    print("Months remaining: 3")
    print("Template: renewal_3_price")
    print("Last objection: Monthly payment too high")
    print("Deferral note: Customer moving house, wants to wait until settled")
    print("\nExpected Mode B Behavior:")
    print("  ✓ Brief acknowledgment of previous price concern")
    print("  ✓ Mention of house move ('hope that went well')")
    print("  ✓ Low-pressure review invitation")
    print("  ✓ No specific figures or promises")
    print("  ✓ Offer visit or call with Loyalty team")
    
    # Scenario 2: Timing deferral
    print("\n\n📝 SCENARIO 2: Post-Christmas deferral")
    print("-" * 80)
    print("Customer: Sarah Williams")
    print("Vehicle: Audi A3 SPORTBACK (AB23XYZ)")
    print("Months remaining: 9")
    print("Template: renewal_9_generic")
    print("Deferral note: Customer said 'maybe after Christmas'")
    print("\nExpected Mode B Behavior:")
    print("  ✓ Reference to waiting until after Christmas")
    print("  ✓ Now that timing has passed, gentle re-engagement")
    print("  ✓ Planning ahead focus (9-month tone)")
    print("  ✓ No pressure, options review")
    
    # Scenario 3: Firm opt-out
    print("\n\n📝 SCENARIO 3: Firm opt-out (STOP)")
    print("-" * 80)
    print("Customer: Alex Thompson")
    print("Inbound message: 'STOP'")
    print("\nExpected Mode B Behavior:")
    print("  ✓ Polite acknowledgment")
    print("  ✓ Confirm won't message again")
    print("  ✓ No further marketing")
    print("  ✓ Thank them for letting us know")
    
    # Scenario 4: Positive intent
    print("\n\n📝 SCENARIO 4: Positive intent booking")
    print("-" * 80)
    print("Customer: Emma Davis")
    print("Vehicle: Audi Q4 e-tron (EV24ABC)")
    print("Inbound message: 'Yes I'm interested, can we book in?'")
    print("\nExpected Mode B Behavior:")
    print("  ✓ Warm acknowledgment")
    print("  ✓ Offer 2 options: showroom visit OR call")
    print("  ✓ Ask for day/time preference")
    print("  ✓ Professional, friendly tone")
    
    print("\n" + "=" * 80)
    print("KEY MODE B FEATURES")
    print("=" * 80)
    print("\n✅ Template-led: Always starts from approved template body")
    print("✅ Context-aware: References past objections, deferrals, appointments")
    print("✅ Smart adaptation: Light personalization without changing core message")
    print("✅ Brand protection: No figures, low-pressure, professional")
    print("✅ Conversation memory: Remembers lost sale reasons, timing requests")
    print("\n" + "=" * 80)

if __name__ == "__main__":
    test_mode_b_scenarios()
