"""
Test d'intégration du PatternManager - Version Windows
"""

print("="*70)
print("[TEST] INTEGRATION PATTERNMANAGER")
print("="*70)

# Test imports
print("\n[1/5] Test imports...")
try:
    from pattern_manager import get_pattern_manager
    print("   [OK] Modules importés")
except Exception as e:
    print(f"   [ERR] {e}")
    exit(1)

# Test instance
print("\n[2/5] Test instance...")
try:
    pm = get_pattern_manager()
    print(f"   [OK] {len(pm.patterns)} patterns chargés")
except Exception as e:
    print(f"   [ERR] {e}")
    exit(1)

# Test validation
print("\n[3/5] Test validation patterns...")
try:
    allowed1, reason1 = pm.is_pattern_allowed('EARLY_BREAKOUT', 50)
    allowed2, reason2 = pm.is_pattern_allowed('END_OF_CYCLE', 100)
    print(f"   [OK] EARLY_BREAKOUT(50): {'PASS' if allowed1 else 'BLOCKED'}")
    print(f"   [OK] END_OF_CYCLE(100): {'PASS' if allowed2 else 'BLOCKED'}")
except Exception as e:
    print(f"   [ERR] {e}")
    exit(1)

# Test enregistrement
print("\n[4/5] Test enregistrement...")
try:
    pm.record_signal('TEST_PATTERN')
    pm.record_trade('TEST_PATTERN', 1.5)
    stats = pm.get_pattern_stats('TEST_PATTERN')
    print(f"   [OK] Signal enregistré")
    print(f"   [OK] Trade enregistré (WR={stats['stats']['win_rate']}%)")
except Exception as e:
    print(f"   [ERR] {e}")
    exit(1)

# Test intégration trading_bot
print("\n[5/5] Test intégration trading_bot.py...")
try:
    with open('trading_bot.py', 'r', encoding='utf-8') as f:
        content = f.read()
    
    checks = [
        ('from pattern_manager import get_pattern_manager', 'Import'),
        ('pm = get_pattern_manager()', 'Utilisation'),
        ('pm.is_pattern_allowed', 'Validation'),
        ('pm.record_signal', 'Signaux'),
        ('pm.record_trade', 'Trades'),
    ]
    
    all_ok = True
    for code, desc in checks:
        if code in content:
            print(f"   [OK] {desc}")
        else:
            print(f"   [ERR] {desc} manquant")
            all_ok = False
    
    if not all_ok:
        exit(1)
        
except Exception as e:
    print(f"   [ERR] {e}")
    exit(1)

print("\n" + "="*70)
print("[OK] TOUS LES TESTS PASSÉS")
print("="*70)
print("\nRésumé:")
print("  [OK] Modules fonctionnels")
print("  [OK] Validation opérationnelle")
print("  [OK] Enregistrement OK")
print("  [OK] Intégration complète")
print("\n[READY] Le PatternManager est prêt !")
print("="*70)
