"""
Per-agent tool configuration.
All agents have FULL standard stack + specialized tools.
Each agent is a platform with own site, channels, database, users.
"""

# FULL standard stack - available to ALL agents
FULL_STANDARD_STACK = [
    # Search & Knowledge (Priority 1)
    "memory_search",
    "graph_query",
    
    # Web Research (Priority 2)
    "web_search",
    "web_extract",
    "crawl4ai_scrape",
    
    # Memory
    "remember_fact",
    
    # Content Generation
    "image_generate",
    "tts_speak",
    
    # Presentations
    "presentation_create",
    "presentation_status",
    "presentation_download",

    # File artifacts
    "file_tool",
]

# Specialized tools per agent (on top of standard stack)
AGENT_SPECIALIZED_TOOLS = {
    # Helion - Energy platform
    # Specialized: energy calculations, solar/wind analysis
    "helion": ['comfy_generate_image', 'comfy_generate_video'],
    
    # Alateya - R&D Lab OS
    # Specialized: experiment tracking, hypothesis testing
    "alateya": ['comfy_generate_image', 'comfy_generate_video'],
    
    # Nutra - Health & Nutrition
    # Specialized: nutrition calculations, supplement analysis
    "nutra": ['comfy_generate_image', 'comfy_generate_video'],
    
    # AgroMatrix - Agriculture
    # Specialized: crop analysis, weather integration, field mapping + plant intelligence
    "agromatrix": [
        'comfy_generate_image',
        'comfy_generate_video',
        'plantnet_lookup',
        'nature_id_identify',
        'gbif_species_lookup',
        'agrovoc_lookup',
    ],
    
    # GreenFood - Food & Eco
    # Specialized: recipe analysis, eco-scoring
    "greenfood": ['comfy_generate_image', 'comfy_generate_video'],
    
    # Druid - Knowledge Search
    # Specialized: deep RAG, document comparison
    "druid": ['comfy_generate_image', 'comfy_generate_video'],
    
    # DaarWizz - DAO Coordination
    # Specialized: governance tools, voting, treasury
    "daarwizz": ['comfy_generate_image', 'comfy_generate_video'],
    
    # Clan - Community
    # Specialized: event management, polls, member tracking
    "clan": ['comfy_generate_image', 'comfy_generate_video'],
    
    # Eonarch - Philosophy & Evolution
    # Specialized: concept mapping, timeline analysis
    "eonarch": ['comfy_generate_image', 'comfy_generate_video'],
    
    # SenpAI (Gordon Senpai) - Trading & Markets
    # Specialized: real-time market data, features, signals
    "senpai": ['market_data', 'comfy_generate_image', 'comfy_generate_video'],

    # 1OK - Window Master Assistant
    # Specialized: CRM flow, quoting, PDF docs, scheduling
    "oneok": [
        "crm_search_client",
        "crm_upsert_client",
        "crm_upsert_site",
        "crm_upsert_window_unit",
        "crm_create_quote",
        "crm_update_quote",
        "crm_create_job",
        "calc_window_quote",
        "docs_render_quote_pdf",
        "docs_render_invoice_pdf",
        "schedule_propose_slots",
        "schedule_confirm_slot",
    ],
    
    # Soul / Athena - Spiritual Mentor
    "soul": ['comfy_generate_image', 'comfy_generate_video'],
    
    # Yaromir - Tech Lead
    "yaromir": ['comfy_generate_image', 'comfy_generate_video'],
    
    # Sofiia - Chief AI Architect
    "sofiia": ['comfy_generate_image', 'comfy_generate_video'],
    
    # Daarion - Media Generation
    "daarion": ['comfy_generate_image', 'comfy_generate_video'],
}

# CrewAI team structure per agent (future implementation)
AGENT_CREW_TEAMS = {
    "helion": {
        "team_name": "Energy Specialists",
        "agents": ["analyst", "engineer", "market_researcher", "communicator"]
    },
    "alateya": {
        "team_name": "Research Professors",
        "agents": ["prof_erudite", "prof_analyst", "prof_creative", "prof_optimizer", "prof_communicator"]
    },
    "nutra": {
        "team_name": "Health Advisors",
        "agents": ["nutritionist", "biochemist", "fitness_coach", "communicator"]
    },
    "agromatrix": {
        "team_name": "Agro Experts",
        "agents": ["agronomist", "soil_specialist", "weather_analyst", "market_analyst"]
    },
    "greenfood": {
        "team_name": "Food & Eco Team",
        "agents": ["chef", "nutritionist", "eco_analyst", "supply_chain"]
    },
    "druid": {
        "team_name": "Knowledge Seekers",
        "agents": ["researcher", "fact_checker", "synthesizer", "archivist"]
    },
    "daarwizz": {
        "team_name": "DAO Operations",
        "agents": ["governance", "treasury", "community", "tech_ops"]
    },
    "clan": {
        "team_name": "Community Spirits",
        "agents": ["welcomer", "mediator", "event_organizer", "historian"]
    },
    "eonarch": {
        "team_name": "Consciousness Guides",
        "agents": ["philosopher", "futurist", "integrator", "storyteller"]
    },
}


def get_agent_tools(agent_id: str) -> list:
    """Get all tools for an agent: standard stack + specialized."""
    specialized = AGENT_SPECIALIZED_TOOLS.get(agent_id, [])
    return FULL_STANDARD_STACK + specialized


def is_tool_allowed(agent_id: str, tool_name: str) -> bool:
    """Check if a tool is allowed for an agent."""
    allowed = get_agent_tools(agent_id)
    return tool_name in allowed


def get_agent_crew(agent_id: str) -> dict:
    """Get CrewAI team configuration for an agent."""
    return AGENT_CREW_TEAMS.get(agent_id, {"team_name": "Default", "agents": []})
