//! Guest SDK for building Kailash WASM plugins.
//!
//! This crate provides the types, error handling, ABI boilerplate, and the
//! `#[kailash_plugin]` proc-macro for compiling Rust code into WASM modules
//! loadable by the Kailash plugin host (`kailash-plugin`).
//!
//! # Architecture
//!
//! A Kailash WASM plugin is a `.wasm` file that exports three functions:
//!
//! - `kailash_alloc(size: i32) -> i32` -- allocate memory in the guest
//! - `kailash_free(ptr: i32, size: i32)` -- free guest memory
//! - `kailash_execute(input_ptr, input_len, out_ptr, out_len) -> i32`
//!   -- execute the plugin logic
//!
//! The [`abi`] module provides these exports automatically. Plugin authors
//! only need to write a function with the signature:
//!
//! ```ignore
//! fn my_plugin(inputs: GuestValueMap) -> Result<GuestValueMap, PluginError>
//! ```
//!
//! and annotate it with `#[kailash_plugin(name = "my-plugin")]`.
//!
//! # Quick start
//!
//! ```ignore
//! use kailash_plugin_guest::prelude::*;
//!
//! #[kailash_plugin(name = "echo", description = "Echoes inputs")]
//! fn echo(inputs: GuestValueMap) -> Result<GuestValueMap, PluginError> {
//!     Ok(inputs)
//! }
//! ```
//!
//! Build with:
//!
//! ```bash
//! cargo build --target wasm32-wasip1 --release
//! ```
//!
//! # Crate structure
//!
//! - [`value`] -- [`GuestValue`](value::GuestValue) enum and [`GuestValueMap`](value::GuestValueMap) type alias
//! - [`error`] -- [`PluginError`](error::PluginError) for structured error reporting
//! - [`abi`] -- WASM ABI exports (`kailash_alloc`, `kailash_free`) and [`execute_with_fn`](abi::execute_with_fn) trampoline

#![deny(clippy::todo, clippy::unimplemented)]
#![warn(missing_docs)]
// ABI code requires unsafe blocks and #[no_mangle] exports
#![allow(unsafe_code)]
#![allow(clippy::manual_let_else)]

pub mod abi;
pub mod error;
pub mod value;

/// Convenience re-exports for plugin authors.
///
/// Import everything a plugin needs with:
///
/// ```
/// use kailash_plugin_guest::prelude::*;
/// # // Verify the prelude items are accessible
/// # fn _check() {
/// #     let _: fn() -> kailash_plugin_guest::value::GuestValueMap = kailash_plugin_guest::value::GuestValueMap::new;
/// # }
/// ```
pub mod prelude {
    pub use kailash_plugin_macros::kailash_plugin;

    pub use crate::{
        error::PluginError,
        value::{GuestValue, GuestValueMap},
    };
}
