// @generated — tool visibility owner authority bridge
// Generated by `xtask protocol-codegen`

#[cfg(all(meerkat_internal_generated_authority_bridge, not(test)))]
#[allow(improper_ctypes_definitions, unsafe_code)]
unsafe extern "Rust" {
    #[link_name = concat!("__meerkat_runtime_generated_authority_bridge_token_is_valid_v1_tool_visibility_owner_", env!("MEERKAT_GENERATED_AUTHORITY_BRIDGE_SYMBOL_SUFFIX"))]
    fn runtime_tool_visibility_owner_generated_authority_bridge_token_is_valid(
        token: &(dyn std::any::Any + Send + Sync),
    ) -> bool;
}

#[cfg(all(meerkat_internal_generated_authority_bridge, not(test)))]
#[doc(hidden)]
#[allow(improper_ctypes_definitions, unsafe_code)]
#[unsafe(export_name = concat!("__meerkat_core_runtime_generated_tool_visibility_owner_build_v1_", env!("MEERKAT_GENERATED_AUTHORITY_BRIDGE_SYMBOL_SUFFIX")))]
pub extern "Rust" fn runtime_generated_tool_visibility_owner_build(
    token: &'static (dyn std::any::Any + Send + Sync),
    owner: std::sync::Arc<dyn crate::tool_scope::ToolVisibilityOwner>,
) -> Result<crate::tool_scope::GeneratedToolVisibilityOwner, String> {
    validate_runtime_tool_visibility_owner_bridge_token(token)?;
    Ok(crate::tool_scope::GeneratedToolVisibilityOwner::from_generated_authority(owner))
}

#[cfg(all(meerkat_internal_generated_authority_bridge, not(test)))]
fn validate_runtime_tool_visibility_owner_bridge_token(
    token: &(dyn std::any::Any + Send + Sync),
) -> Result<(), String> {
    #[allow(unsafe_code)]
    let valid =
        unsafe { runtime_tool_visibility_owner_generated_authority_bridge_token_is_valid(token) };
    if valid {
        Ok(())
    } else {
        Err("generated tool visibility owner requires the generated MeerkatMachine protocol bridge token".into())
    }
}
