use super::{SnowIDConfig, SnowIDConfigError};
pub(super) const DEFAULT_NODE_BITS: u8 = 10;
pub(super) const DEFAULT_CUSTOM_EPOCH: u64 = 1704067200000;
#[derive(Debug)]
pub struct SnowIDConfigBuilder {
pub(super) node_bits: u8,
pub(super) custom_epoch: u64,
}
impl SnowIDConfigBuilder {
pub const fn new() -> Self {
Self {
node_bits: DEFAULT_NODE_BITS,
custom_epoch: DEFAULT_CUSTOM_EPOCH,
}
}
pub fn node_bits(mut self, bits: u8) -> Result<Self, SnowIDConfigError> {
if !(6..=16).contains(&bits) {
return Err(SnowIDConfigError::InvalidNodeBits { bits });
}
self.node_bits = bits;
Ok(self)
}
pub const fn epoch(mut self, epoch: u64) -> Self {
self.custom_epoch = epoch;
self
}
pub fn build(self) -> SnowIDConfig {
SnowIDConfig::new(self.node_bits, self.custom_epoch)
}
}
impl Default for SnowIDConfigBuilder {
fn default() -> Self {
Self::new()
}
}