use crate::ipc_types::Announce as AnnounceBlob;
use thiserror::Error;

/// Errors that may occur when serializing or sending announcement
#[derive(Debug, Error)]
pub enum AnnounceError {
    #[error("failed to serialize Announce JSON: {0}")]
    Json(#[from] serde_json::Error),
}

/// Send the module's announcement blob to the orchestrator via **stdout**.
///
/// This will write a single-line JSON message and flush stdout.
pub fn send_announce(announce: &AnnounceBlob) -> Result<(), AnnounceError> {
    let json = serde_json::to_string(announce)?;
    // Use safe_log to ensure secrets are redacted (if any) and log to stderr
    // But announcement must go to stdout, so we bypass safe_log and print raw JSON
    println!("{}", json);
    Ok(())
}
