use crate::skill::Skill;
use std::collections::HashMap;

pub struct SkillRegistry {
    skills: HashMap<String, Box<dyn Skill>>,
}

impl SkillRegistry {
    pub fn new() -> Self {
        Self {
            skills: HashMap::new(),
        }
    }

    pub fn register(&mut self, skill: Box<dyn Skill>) {
        self.skills.insert(skill.id().0.to_string(), skill);
    }

    pub fn get(&self, id: &str) -> Option<&dyn Skill> {
        self.skills.get(id).map(|s| s.as_ref())
    }

    pub fn all_ids(&self) -> Vec<&str> {
        self.skills.keys().map(|s| s.as_str()).collect()
    }

    pub fn default_registry() -> Self {
        let mut reg = Self::new();
        use crate::skills::*;
        reg.register(Box::new(SieveSkill));
        reg.register(Box::new(CartographSkill));
        reg.register(Box::new(ChiselSkill));
        reg.register(Box::new(SedimentSkill));
        reg.register(Box::new(PrismSkill));
        reg.register(Box::new(CompassSkill));
        reg.register(Box::new(CondenserSkill));
        reg.register(Box::new(ArchivistSkill));
        reg.register(Box::new(ScoutSkill));
        reg.register(Box::new(ChroniclerSkill));
        reg.register(Box::new(AlchemistSkill));
        reg.register(Box::new(SentinelSkill));
        reg.register(Box::new(CartridgeSkill));
        reg.register(Box::new(ResonatorSkill));
        reg.register(Box::new(SurveyorSkill));
        reg
    }
}

impl Default for SkillRegistry {
    fn default() -> Self {
        Self::default_registry()
    }
}
