---
source: tests/backends_swift_snapshot_test.rs
expression: "&file.content"
---
// Generated by alef. Do not edit by hand.

#![allow(unused_variables, unreachable_code, unreachable_patterns)]
#![allow(
    clippy::collapsible_if,
    clippy::collapsible_match,
    clippy::needless_borrows_for_generic_args,
    clippy::field_reassign_with_default,
    clippy::too_many_arguments,
    clippy::clone_on_copy,
    clippy::unnecessary_cast,
    clippy::manual_flatten,
    clippy::match_single_binding,
    clippy::redundant_closure,
    clippy::useless_conversion,
    clippy::inherent_to_string,
)]


/// Process-wide tokio runtime shared across every swift-bridge async wrapper.
///
/// alef-emitted; see shims.rs for the rationale (orphaned reqwest connection
/// pools when each call creates and drops its own current-thread runtime).
fn __alef_tokio_runtime() -> &'static ::tokio::runtime::Runtime {
    use std::sync::OnceLock;
    static RT: OnceLock<::tokio::runtime::Runtime> = OnceLock::new();
    RT.get_or_init(|| {
        ::tokio::runtime::Builder::new_multi_thread()
            .enable_all()
            .build()
            .expect("build process-wide alef tokio runtime")
    })
}

#[swift_bridge::bridge]
mod ffi {
    extern "Rust" {
        type SystemMessage;
        #[swift_bridge(init)]
        fn new(content: String, name: Option<String>) -> SystemMessage;
        fn content(&self) -> String;
        fn name(&self) -> Option<String>;
    }

    extern "Rust" {
        #[swift_bridge(swift_name = "systemMessageFromJson")]
        fn system_message_from_json(json: String) -> Result<SystemMessage, String>;
    }
}


pub struct SystemMessage(pub demo::SystemMessage);
impl SystemMessage {
    pub fn new(content: String, name: Option<String>) -> SystemMessage {
        let mut __target: demo::SystemMessage = ::std::default::Default::default();
        {
            // Try JSON parse first (handles enum/object values); on parse failure
            // treat the raw input as a JSON string scalar so plain `String` /
            // string-like enum fields don't end up empty for inputs that aren't
            // valid JSON tokens (e.g. `tts-1`).
            let __v = ::serde_json::from_str::<::serde_json::Value>(&content)
                .unwrap_or(::serde_json::Value::String(content.clone()));
            if let Ok(t) = ::serde_json::from_value(__v) { __target.content = t; }
        }
        if let Some(s) = name {
            // Try JSON parse first (handles enum/object values); on parse failure
            // treat the raw input as a JSON string scalar so plain `String` /
            // string-like enum fields don't end up empty for inputs that aren't
            // valid JSON tokens (e.g. `tts-1`).
            let __v = ::serde_json::from_str::<::serde_json::Value>(&s)
                .unwrap_or(::serde_json::Value::String(s));
            if let Ok(t) = ::serde_json::from_value(__v) { __target.name = Some(t); }
        }
        SystemMessage(__target)
    }
    pub fn content(&self) -> String {
        self.0.content.clone()
    }
    pub fn name(&self) -> Option<String> {
        self.0.name.clone()
    }
}

pub fn system_message_from_json(json: String) -> Result<SystemMessage, String> {
    serde_json::from_str::<demo::SystemMessage>(&json)
        .map(SystemMessage)
        .map_err(|e| e.to_string())
}
