wit_bindgen::generate!({
    world: "mobile-sdk",
    path: "wit"
});

#[cfg(feature = "mobile")]
struct HubroMobileSdk;

#[cfg(feature = "mobile")]
export!(HubroMobileSdk);

#[cfg(feature = "mobile")]
impl exports::local::hubro_sdk::mobile_sdk_api::Guest for HubroMobileSdk {
    // fn allocate(size: u32) -> u32 {
    //     mobile::allocate(size as usize) as usize as u32
    // }
    //
    // fn dealloc(ptr: u32, cap: u32) {
    //     mobile::dealloc(ptr as usize as *mut std::os::raw::c_void, cap as usize)
    // }

    fn fetch_records_count(record_type: i32, from: i32, to: i32) -> i32 {
        mobile::fetch_records_count(record_type, from, to)
    }

    fn get_usage_data_count(from: i32, to: i32) -> i32 {
        mobile::get_usage_data_count(from, to)
    }

    fn debug_print_line(output: String) {
        mobile::debug_print_line(&output)
    }

    fn get_current_platform() -> exports::local::hubro_sdk::mobile_sdk_api::Platform {
        match mobile::get_current_platform() {
            mobile::Platform::IOS => exports::local::hubro_sdk::mobile_sdk_api::Platform::Ios,
            mobile::Platform::Android => {
                exports::local::hubro_sdk::mobile_sdk_api::Platform::Android
            }
            mobile::Platform::JS => exports::local::hubro_sdk::mobile_sdk_api::Platform::Js,
            mobile::Platform::Unknown => {
                exports::local::hubro_sdk::mobile_sdk_api::Platform::Unknown
            }
        }
    }

    fn load_model(path: String) -> i32 {
        mobile::load_model(&path)
    }

    fn run_inference(model_id: i32, input: Vec<f32>, shape: Vec<i32>, output_len: i32) -> Vec<f32> {
        let mut output = vec![0.0; output_len.max(0) as usize];
        let _ = mobile::run_inference(model_id, &input, &shape, &mut output);
        output
    }

    fn upload_key(server_key: Vec<u8>) -> i32 {
        local::hubro_sdk::mobile_host::upload_server_key(&server_key)
    }

    fn get_current_time_nanos() -> u64 {
        mobile::get_current_time_nanos()
    }

    fn quantize_float_to_u16(weight: f32, x_min: f32, x_max: f32) -> u16 {
        mobile::quantize_float_to_u16(weight, x_min, x_max)
    }
}

#[cfg(feature = "server")]
pub mod fhir;
#[cfg(feature = "server")]
pub mod plugin;
#[cfg(feature = "server")]
pub mod signals;
#[cfg(feature = "server")]
pub mod toolbox;
#[cfg(feature = "mobile")]
pub mod mobile;
#[cfg(feature = "mobile")]
pub mod records;
#[cfg(feature = "mobile")]
pub mod fed;
#[cfg(all(feature = "mobile", not(all(target_os = "wasi", target_env = "p2"))))]
pub use tfhe;
#[cfg(feature = "mobile")]
pub use burn;
#[cfg(feature = "mobile")]
pub use polars;
#[cfg(feature = "mobile")]
pub use linfa;
#[cfg(feature = "mobile")]
pub use linfa_clustering;
#[cfg(feature = "mobile")]
pub use linfa_logistic;
#[cfg(feature = "mobile")]
pub use ndarray;
#[cfg(feature = "mobile")]
pub use chrono;
#[cfg(feature = "mobile")]
pub use ml_kem;
#[cfg(feature = "mobile")]
pub use ml_dsa;
#[cfg(feature = "mobile")]
pub use chacha20poly1305_nostd;
#[cfg(feature = "mobile")]
pub use rand;