use std::collections::HashMap;

use data::prop_type::PROP_LEVEL;
use proto::{avatar_bin::Detail, AvatarBin, TrialAvatarBin};

use crate::creature::property::append_int_prop_value;

use super::BaseAvatar;

#[derive(Default)]
pub struct TrialAvatar {
    pub base: BaseAvatar,
    pub trial_avatar_id: u32,
    pub is_inherit: bool,
}

impl TrialAvatar {
    pub fn to_client(&self) -> proto::AvatarInfo {
        let mut map = HashMap::new();
        append_int_prop_value(&mut map, PROP_LEVEL, self.base.level.into());

        self.base.to_client(map)
    }

    pub fn from_bin(bin: AvatarBin, detail_bin: TrialAvatarBin) -> Self {
        Self {
            base: BaseAvatar::from_bin(bin),
            trial_avatar_id: detail_bin.trial_avatar_id,
            is_inherit: detail_bin.is_inherit,
        }
    }

    pub fn to_bin(&self) -> AvatarBin {
        self.base.to_bin(Detail::TrialAvatar(TrialAvatarBin {
            trial_avatar_id: self.trial_avatar_id,
            is_inherit: self.is_inherit,
            ..Default::default()
        }))
    }
}
