use indexmap::IndexMap;
use crate::{property::NoMeta, BinObject, PropertyValueEnum};
#[derive(Debug, Clone)]
pub struct Builder<M = NoMeta> {
path_hash: u32,
class_hash: u32,
properties: IndexMap<u32, PropertyValueEnum<M>>,
}
impl<M> Builder<M> {
pub fn new(path_hash: u32, class_hash: u32) -> Self {
Self {
path_hash,
class_hash,
properties: IndexMap::new(),
}
}
pub fn path_hash(mut self, path_hash: u32) -> Self {
self.path_hash = path_hash;
self
}
pub fn class_hash(mut self, class_hash: u32) -> Self {
self.class_hash = class_hash;
self
}
pub fn property(mut self, name_hash: u32, value: impl Into<PropertyValueEnum<M>>) -> Self {
self.properties.insert(name_hash, value.into());
self
}
pub fn properties(
mut self,
props: impl IntoIterator<Item = (u32, PropertyValueEnum<M>)>,
) -> Self {
self.properties.extend(props);
self
}
pub fn build(self) -> BinObject<M> {
BinObject {
path_hash: self.path_hash,
class_hash: self.class_hash,
properties: self.properties,
}
}
}