use std::{cell::Cell, rc::Rc};

#[derive(Clone)]
pub(crate) struct UniqueIdGenerator {
    last_id: Rc<Cell<u64>>,
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct UniqueId(u64);

impl UniqueIdGenerator {
    pub(crate) fn new() -> Self {
        Self {
            last_id: Rc::new(Cell::new(0)),
        }
    }

    pub(crate) fn generate(&self) -> UniqueId {
        let unique_id = self.last_id.get() + 1;
        self.last_id.set(unique_id);
        UniqueId(unique_id)
    }
}
