pub mod redis_registry;

use anyhow::Result;
use bloomfilter::Bloom;
use std::sync::Mutex;

pub struct BloomFilterCache {
    inner: Mutex<Bloom<String>>,
}

impl BloomFilterCache {
    pub fn new(expected_items: usize, fp_rate: f64) -> Result<Self> {
        if fp_rate <= 0.0 || fp_rate >= 1.0 {
            return Err(anyhow::anyhow!(
                "fp_rate must be between 0 and 1 (exclusive), got {}",
                fp_rate
            ));
        }
        if expected_items == 0 {
            return Err(anyhow::anyhow!("expected_items must be greater than 0"));
        }
        Ok(Self {
            inner: Mutex::new(Bloom::new_for_fp_rate(expected_items, fp_rate)),
        })
    }

    pub fn check(&self, item: &str) -> bool {
        self.inner.lock().unwrap().check(&item.to_string())
    }

    pub fn set(&self, item: &str) {
        self.inner.lock().unwrap().set(&item.to_string());
    }
}
