//! Example service that imports the versioned Wasmeld monotonic-clock capability.
//!
//! Each response is eight little-endian timestamp bytes followed by the input.
//! The timestamp is Actor-local monotonic time, not a Unix timestamp.

mod bindings {
    // This macro generates Rust ABI adapters at compile time from the
    // materialized local WIT graph. It does not make a remote protocol call or
    // embed the WIT source files; the Component carries canonical ABI types.
    wit_bindgen::generate!({
        path: "wit",
        world: "clock-probe-component",
        generate_all,
    });
}

struct ClockProbe;

impl bindings::Guest for ClockProbe {
    fn init(_config: Vec<u8>) -> Result<(), bindings::ServiceError> {
        Ok(())
    }

    fn invoke(input: Vec<u8>) -> Result<Vec<u8>, bindings::ServiceError> {
        let now = bindings::wasmeld::clock::monotonic_clock::now();
        let mut output = now.to_le_bytes().to_vec();
        output.extend_from_slice(&input);
        Ok(output)
    }
}

bindings::export!(ClockProbe with_types_in bindings);
