//! Rhai integration for the virt package
//!
//! This module provides Rhai wrappers for virtualization and containerization functions,
//! enabling scripting access to Buildah, Nerdctl, QCOW2, Cloud Hypervisor, and Kubernetes operations.

use rhai::{Engine, EvalAltResult};

pub use crate::buildah::rhai as buildah;
pub use crate::cloudhv::rhai as cloudhv;
pub use crate::nerdctl::rhai as nerdctl;
pub use crate::qcow2::rhai as qcow2;
pub use crate::virt_what::rhai as virt_what;

#[cfg(feature = "kubernetes")]
pub use crate::kubernetes::rhai as kubernetes;

// Re-export common types and functions for convenience
pub use buildah::{Bah, bah_fluent_new_with_executor};

/// Register all virt module functions with the Rhai engine
///
/// This is a convenience function that registers all available virtualization modules
/// at once.
///
/// # Arguments
///
/// * `engine` - The Rhai engine to register the functions with
///
/// # Returns
///
/// * `Result<(), Box<EvalAltResult>>` - Ok if registration was successful, Err otherwise
pub fn register(engine: &mut Engine) -> Result<(), Box<EvalAltResult>> {
    buildah::register_bah_module(engine)?;
    nerdctl::register_nerdctl_module(engine)?;
    qcow2::register_qcow2_module(engine)?;
    cloudhv::register_cloudhv_module(engine)?;
    virt_what::register_virtwhat_module(engine)?;

    #[cfg(feature = "kubernetes")]
    kubernetes::register_kubernetes_module(engine)?;

    Ok(())
}

// Legacy name for backwards compatibility
pub fn register_virt_module(engine: &mut Engine) -> Result<(), Box<EvalAltResult>> {
    register(engine)
}
