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