/// Facade trait for sending contact-form emails from Leptos server functions.
///
/// Defined here in `rustelo_components_leptos` so UI components can trigger
/// email sends without a direct dependency on `rustelo_server`. The concrete
/// adapter lives in `rustelo_server` and is injected at startup as
/// `axum::Extension<ContactFormExtension>`.
#[cfg(feature = "ssr")]
pub mod server {
    use std::future::Future;
    use std::pin::Pin;
    use std::sync::Arc;

    pub type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;

    /// Minimal email-send abstraction required by contact-form server
    /// functions.
    pub trait ContactFormFacade: Send + Sync {
        fn send(
            &self,
            name: String,
            email: String,
            subject: String,
            message: String,
        ) -> BoxFuture<Result<(), String>>;
    }

    /// Axum `Extension` wrapper enabling
    /// `extract::<Extension<ContactFormExtension>>()` inside `#[server]`
    /// functions.
    #[derive(Clone)]
    pub struct ContactFormExtension(pub Arc<dyn ContactFormFacade>);
}
