use std::collections::HashMap;

use proto::AvatarBin;

use super::Skill;

#[derive(Default)]
pub struct SkillComp {
    cur_skill_depot_id: u32,
    pub skill_map: HashMap<u32, Skill>,
}

impl SkillComp {
    pub fn init_skill_depot(&mut self, skill_depot_id: u32) {
        let depot_data = data::iter_avatar_skill_depot_data()
            .find(|d| d.id == skill_depot_id)
            .unwrap();

        self.skill_map.clear();
        self.cur_skill_depot_id = skill_depot_id;

        self.skill_map.extend(
            depot_data
                .skills
                .iter()
                .filter(|id| **id != 0)
                .map(|id| (*id, Skill::new(*id))),
        );

        self.skill_map.extend(
            depot_data
                .sub_skills
                .iter()
                .filter(|id| **id != 0)
                .map(|id| (*id, Skill::new(*id))),
        );

        if depot_data.energy_skill != 0 {
            self.skill_map
                .insert(depot_data.energy_skill, Skill::new(depot_data.energy_skill));
        }
    }

    pub fn to_bin(&self, _bin: &mut AvatarBin) {
        // TODO
    }

    pub fn from_bin(_bin: &AvatarBin) -> Self {
        Self::default() // TODO!
    }
}
