use std::collections::HashMap;

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

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

use super::BaseAvatar;

#[derive(Default)]
pub struct MirrorAvatar {
    pub base: BaseAvatar,
    pub avatar_snapshot_type: u32,
}

impl MirrorAvatar {
    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: MirrorAvatarBin) -> Self {
        Self {
            base: BaseAvatar::from_bin(bin),
            avatar_snapshot_type: detail_bin.avatar_snapshot_type,
        }
    }

    pub fn to_bin(&self) -> AvatarBin {
        self.base.to_bin(Detail::MirrorAvatar(MirrorAvatarBin {
            avatar_snapshot_type: self.avatar_snapshot_type,
        }))
    }
}
