use std::sync::Once;

use pdfium_bind_sys as ffi;

/// RAII guard for PDFium library initialization.
///
/// Initializes the PDFium library on first call. Multiple calls are safe —
/// the underlying `FPDF_InitLibrary` is invoked at most once per process.
///
/// # Example
///
/// ```no_run
/// let _lib = pdfium_bind::Library::init();
/// // PDFium is now ready to use
/// ```
pub struct Library;

static INIT: Once = Once::new();

impl Library {
    /// Initialize the PDFium library.
    ///
    /// This must be called before any other pdfium-bind operation.
    /// Calling it multiple times is harmless.
    pub fn init() -> Self {
        INIT.call_once(|| unsafe { ffi::FPDF_InitLibrary() });
        Library
    }
}
