use crate::{Cid, GetType, KeyScheme, Record, Typ, record::record_types_tuple};

#[derive(Debug, Clone, Copy)]
pub struct EntityAttribute {
    pub name: &'static str,
    pub key_scheme: KeyScheme,
    pub ty: Typ,
    pub group_bits: u32,
    pub version: u16,
}

impl EntityAttribute {
    pub const fn from_ty<Item: Record + GetType>() -> EntityAttribute {
        let name = <Item as Record>::NAME;
        let (key_scheme, ty) = record_types_tuple::<Item>();
        let group_bits = <<Item as Record>::SelfId as Cid>::GROUP_BITS;
        let version = <Item as Record>::VERSION;

        EntityAttribute {
            name,
            key_scheme,
            ty,
            group_bits,
            version,
        }
    }
}
