//! Pre-summarized PoE2 game knowledge for LLM context.
//!
//! Provides curated summaries of game mechanics optimized
//! for inclusion in LLM prompts.

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Knowledge base containing all summarized concepts.
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct KnowledgeBase {
    pub damage_types: Vec<DamageType>,
    pub defense_layers: Vec<DefenseLayer>,
    pub skill_tags: Vec<SkillTag>,
    pub classes: Vec<ClassInfo>,
    pub archetypes: Vec<BuildArchetype>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DamageType {
    pub name: String,
    pub description: String,
    pub scaling_stats: Vec<String>,
    pub conversion_sources: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DefenseLayer {
    pub name: String,
    pub description: String,
    pub effective_against: Vec<String>,
    pub sources: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SkillTag {
    pub name: String,
    pub description: String,
    pub affected_by: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClassInfo {
    pub name: String,
    pub base_stats: HashMap<String, i32>,
    pub ascendancies: Vec<AscendancyInfo>,
    pub typical_archetypes: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AscendancyInfo {
    pub name: String,
    pub description: String,
    pub key_nodes: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BuildArchetype {
    pub name: String,
    pub description: String,
    pub typical_skills: Vec<String>,
    pub key_uniques: Vec<String>,
    pub defense_priorities: Vec<String>,
}

impl KnowledgeBase {
    /// Load the knowledge base from embedded data.
    pub fn load() -> Self {
        // TODO: Load from embedded JSON or build at compile time
        Self::default()
    }

    /// Get a summary for a specific topic.
    pub fn get_summary(&self, topic: &str) -> Option<String> {
        // TODO: Generate contextual summary for the topic
        match topic.to_lowercase().as_str() {
            "damage" => Some(self.summarize_damage_types()),
            "defense" => Some(self.summarize_defenses()),
            _ => None,
        }
    }

    fn summarize_damage_types(&self) -> String {
        // TODO: Generate LLM-friendly summary
        "Damage types: Physical, Fire, Cold, Lightning, Chaos".to_owned()
    }

    fn summarize_defenses(&self) -> String {
        // TODO: Generate LLM-friendly summary
        "Defense layers: Life, ES, Armour, Evasion, Resistances, Block".to_owned()
    }

    /// Get context for a build prompt.
    pub fn get_build_context(&self, _prompt: &str) -> String {
        // TODO: Analyze prompt and return relevant knowledge
        String::new()
    }
}
