use std::{cell::Cell, sync::Once};
use crate::qjs;
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "classes")))]
pub struct ClassId {
    id: Cell<qjs::JSClassID>,
    once: Once,
}
unsafe impl Send for ClassId {}
unsafe impl Sync for ClassId {}
impl ClassId {
    pub const fn new() -> Self {
        Self {
            id: Cell::new(0),
            once: Once::new(),
        }
    }
    pub fn get(&self) -> qjs::JSClassID {
        self.init();
        self.id.get()
    }
    fn init(&self) {
        self.once.call_once(|| {
            let mut id = 0;
            unsafe { qjs::JS_NewClassID(&mut id) };
            self.id.set(id);
        })
    }
}