//! Cross-channel wire shape: assert OutboundReplyKind::VoiceNote
//! deserialises back from JSON cleanly through `nexo-tool-meta`,
//! so the daemon → channel plugin dispatch path stays
//! channel-agnostic.

use base64::Engine;
use nexo_tool_meta::reply_kind::OutboundReplyKind;

#[test]
fn voice_note_round_trips_through_json() {
    let original = OutboundReplyKind::VoiceNote {
        audio_bytes: vec![0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01, 0x02],
        mimetype: "audio/ogg; codecs=opus".to_string(),
        transcript: Some("Hola mundo".to_string()),
    };
    let json = serde_json::to_string(&original).unwrap();
    // base64 of [0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01, 0x02] = 3q2+7wAB Ag
    let expected_b64 = base64::engine::general_purpose::STANDARD
        .encode(&[0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01, 0x02]);
    assert!(json.contains(&expected_b64), "expected base64 encoding in JSON");

    let parsed: OutboundReplyKind = serde_json::from_str(&json).unwrap();
    assert_eq!(parsed, original);
}

#[test]
fn voice_note_mime_string_preserves_codec_hint() {
    let r = OutboundReplyKind::VoiceNote {
        audio_bytes: vec![1, 2, 3],
        mimetype: "audio/ogg; codecs=opus".to_string(),
        transcript: None,
    };
    let json = serde_json::to_string(&r).unwrap();
    assert!(
        json.contains("codecs=opus"),
        "codec hint required by iOS WhatsApp PTT — must survive serde round-trip"
    );
}

#[test]
fn voice_note_kind_label_consistent() {
    let r = OutboundReplyKind::VoiceNote {
        audio_bytes: vec![],
        mimetype: "audio/ogg; codecs=opus".to_string(),
        transcript: None,
    };
    assert_eq!(r.kind_label(), "voice_note");
}

#[test]
fn voice_note_as_text_summary_returns_transcript() {
    let r = OutboundReplyKind::VoiceNote {
        audio_bytes: vec![],
        mimetype: "audio/ogg; codecs=opus".to_string(),
        transcript: Some("transcript content".to_string()),
    };
    assert_eq!(r.as_text_summary(), "transcript content");
}
