use std::collections::HashMap;

use crate::logic::BaseProperty;
use data::tables::{AvatarBaseID, RobotConfigID};
use proto::AvatarUnitInfo;

pub struct AvatarUnit {
    pub avatar_id: AvatarUnitID,
    pub mp_property_override: HashMap<BaseProperty, i32>,
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum AvatarUnitID {
    Base(AvatarBaseID),
    Robot(RobotConfigID),
}

impl AvatarUnitID {
    pub fn base_id(&self) -> AvatarBaseID {
        match *self {
            Self::Base(id) => id,
            Self::Robot(id) => id.template().character_id,
        }
    }
}

impl AvatarUnit {
    pub fn to_client(&self) -> AvatarUnitInfo {
        AvatarUnitInfo {
            avatar_id: match self.avatar_id {
                AvatarUnitID::Base(id) => id.value(),
                AvatarUnitID::Robot(id) => id.value(),
            },
            mp_property_override_map: self
                .mp_property_override
                .iter()
                .map(|(prop, value)| (*prop as u32, *value))
                .collect(),
            ..Default::default()
        }
    }
}
