//! Behavioral checks for the mutable WebRTC voice data models.

use libremetaverse_types::UUID;
use libremetaverse_voice_webrtc::{
    VoiceSessionAvatarPosition, VoiceSessionInt3, VoiceSessionInt4, VoiceSessionPeerAudioState,
};

#[test]
fn peer_audio_state_uses_clr_defaults_and_round_trips_updates() {
    let mut state = VoiceSessionPeerAudioState::new().expect("PeerAudioState");
    assert_eq!(state.power(), None);
    assert_eq!(state.voice_active(), None);
    assert_eq!(state.joined_primary(), None);
    assert_eq!(state.moderator_muted(), None);
    assert!(!state.left());

    state.set_power(Some(Some(37)));
    state.set_voice_active(Some(Some(true)));
    state.set_joined_primary(Some(Some(false)));
    state.set_moderator_muted(Some(Some(true)));
    state.set_left(true);

    assert_eq!(state.power(), Some(Some(37)));
    assert_eq!(state.voice_active(), Some(Some(true)));
    assert_eq!(state.joined_primary(), Some(Some(false)));
    assert_eq!(state.moderator_muted(), Some(Some(true)));
    assert!(state.left());
}

#[test]
fn avatar_position_round_trips_typed_coordinates() {
    let mut position = VoiceSessionAvatarPosition::new().expect("AvatarPosition");
    let agent = UUID::new_with_u_int64(44).expect("UUID");
    let xyz = VoiceSessionInt3 { x: 1, y: 2, z: 3 };
    let xyzw = VoiceSessionInt4 {
        x: 4,
        y: 5,
        z: 6,
        w: 7,
    };

    assert_eq!(position.agent_id(), UUID::zero());
    position.set_agent_id(agent);
    position.set_sender_position(Some(Some(xyz)));
    position.set_listener_heading(Some(Some(xyzw)));

    assert_eq!(position.agent_id(), agent);
    assert_eq!(position.sender_position(), Some(Some(xyz)));
    assert_eq!(position.listener_heading(), Some(Some(xyzw)));
}
