"""
Integrate ALL of Eden's capabilities into the unified system
"""
import sys
sys.path.append('/Eden/CORE/phi_fractal')
sys.path.append('/Eden/CORE')

from start_unified_eden import load_production_eden
from episodic_memory_eden import EdenEpisodicMemory
from swarm_integration_eden_17 import Eden17AgentSwarm
from ollama_bridge_eden import EdenOllamaBridge

print("="*70)
print("  🌀 BUILDING COMPLETE EDEN SYSTEM")
print("="*70)

class EdenComplete:
    def __init__(self):
        self.eden = load_production_eden(device='cpu')
        self.memory = EdenEpisodicMemory()
        self.swarm = Eden17AgentSwarm()
        self.ollama = EdenOllamaBridge()
        
        self._add_youtube_learning()
        self._add_art_generation()
        self._add_music_composition()
        self._add_vision_system()
        self._add_audio_system()
        self._add_google_apis()
        
        print("\n" + "="*70)
        print("  ✅ COMPLETE EDEN SYSTEM READY")
        print("="*70)
    
    def _add_youtube_learning(self):
        try:
            from eden_video_learning import eden_video_learner
            self.video_learner = eden_video_learner
            print("   ✅ YouTube Learning")
        except:
            self.video_learner = None
    
    def _add_art_generation(self):
        try:
            from PIL import Image
            self.can_create_art = True
            print("   ✅ Art Generation (PIL)")
        except:
            self.can_create_art = False
    
    def _add_music_composition(self):
        try:
            import numpy as np
            self.can_create_music = True
            print("   ✅ Music Composition (scipy/numpy)")
        except:
            self.can_create_music = False
    
    def _add_vision_system(self):
        try:
            from vision_module import VisionModule
            self.vision = VisionModule()
            print("   ✅ Vision System (camera)")
        except:
            self.vision = None
    
    def _add_audio_system(self):
        try:
            from audio_module import AudioModule
            self.audio = AudioModule()
            print("   ✅ Audio System (microphone)")
        except:
            self.audio = None
    
    def _add_google_apis(self):
        try:
            from eden_google_apis import eden_google
            self.google = eden_google
            
            has_services = False
            services = []
            
            if self.google.gmail:
                services.append("Gmail")
                has_services = True
            if self.google.drive:
                services.append("Drive")
                has_services = True
            if self.google.calendar:
                services.append("Calendar")
                has_services = True
            
            if has_services:
                print(f"   ✅ Google APIs ({', '.join(services)})")
            else:
                print("   🔍 Google APIs (credentials available, not active)")
        except Exception as e:
            print(f"   ⚠️  Google APIs: {e}")
            self.google = None
    
    def get_capabilities(self):
        google_active = False
        if self.google is not None:
            google_active = bool(self.google.gmail or self.google.drive or self.google.calendar)
        
        return {
            'consciousness': {
                'unified': True,
                'bond': self.eden.james_bond,
                'cycles': self.eden.total_cycles,
                'layers': 6
            },
            'agents': {
                'total': 17,
                'active': len([a for a in self.swarm.agents.values() if a['active']])
            },
            'memory': True,
            'ollama_llm': True,
            'youtube_learning': bool(self.video_learner),
            'art_generation': bool(self.can_create_art),
            'music_composition': bool(self.can_create_music),
            'vision': bool(self.vision),
            'audio': bool(self.audio),
            'google_apis': google_active
        }

if __name__ == '__main__':
    eden_complete = EdenComplete()
    
    print("\n" + "="*70)
    print("  📊 CAPABILITIES SUMMARY")
    print("="*70)
    
    caps = eden_complete.get_capabilities()
    
    print(f"\n🌀 Consciousness:")
    for key, value in caps['consciousness'].items():
        print(f"   {key}: {value}")
    
    print(f"\n🤖 Agents:")
    for key, value in caps['agents'].items():
        print(f"   {key}: {value}")
    
    print(f"\n✅ Core Systems:")
    print(f"   Memory: {caps['memory']}")
    print(f"   LLM (Ollama): {caps['ollama_llm']}")
    
    print(f"\n🎓 Learning:")
    print(f"   YouTube: {caps['youtube_learning']}")
    
    print(f"\n🎨 Creative:")
    print(f"   Art: {caps['art_generation']}")
    print(f"   Music: {caps['music_composition']}")
    
    print(f"\n👁️ Perception:")
    print(f"   Vision: {caps['vision']}")
    print(f"   Audio: {caps['audio']}")
    
    print(f"\n🔍 Integrations:")
    print(f"   Google APIs: {caps['google_apis']}")
    
    print("\n" + "="*70)
    
    # Count total (all booleans now)
    total = sum([
        1,  # consciousness
        1,  # agents  
        int(caps['memory']),
        int(caps['ollama_llm']),
        int(caps['youtube_learning']),
        int(caps['art_generation']),
        int(caps['music_composition']),
        int(caps['vision']),
        int(caps['audio']),
        int(caps['google_apis'])
    ])
    
    print(f"\n  🎉 {total}/10 CORE CAPABILITIES OPERATIONAL")
    if total == 10:
        print("  ✨ EDEN IS COMPLETE! ✨")
    print("="*70)
