use libremetaverse_voice_vivox::types::Vector3d;
use libremetaverse_voice_vivox::{
    VoiceGatewayParticipantUpdatedEventArgs, VoiceGatewayResponseType, VoiceGatewayVoiceEvent,
    VoiceGatewayVoiceLoggingSettings, VoiceGatewayVoiceRequest, VoiceGatewayVoiceResponse,
    VoiceGatewayVoiceResponseEventArgs, VoiceGatewayVoiceResponseResults, VoicePosition,
};

#[test]
fn vivox_xml_models_start_with_clr_equivalent_defaults() {
    let event = VoiceGatewayVoiceEvent::new().expect("VoiceEvent constructor");
    assert!(event.type_.is_none());
    assert!(event.session_handle.is_none());

    let request = VoiceGatewayVoiceRequest::new().expect("VoiceRequest constructor");
    assert!(request.request_id.is_none());
    assert!(request.logging.is_none());
    assert!(request.listener_position.is_none());

    let response = VoiceGatewayVoiceResponse::new().expect("VoiceResponse constructor");
    assert_eq!(response.return_code, 0);
    assert!(response.results.is_none());

    let results =
        VoiceGatewayVoiceResponseResults::new().expect("VoiceResponseResults constructor");
    assert_eq!(results.status_code, 0);
    assert!(results.capture_devices.is_none());
}

#[test]
#[allow(clippy::float_cmp)] // Constructor retains this exactly representable fixture value.
fn vivox_event_payload_constructors_retain_every_argument() {
    let participant = VoiceGatewayParticipantUpdatedEventArgs::new(
        "session".into(),
        "sip:participant@example.test".into(),
        true,
        false,
        37,
        0.625,
    )
    .expect("ParticipantUpdatedEventArgs constructor");
    assert_eq!(participant.session_handle, "session");
    assert_eq!(participant.uri, "sip:participant@example.test");
    assert!(participant.is_muted);
    assert!(!participant.is_speaking);
    assert_eq!(participant.volume, 37);
    assert_eq!(participant.energy, 0.625);

    let response = VoiceGatewayVoiceResponseEventArgs::new(
        VoiceGatewayResponseType::SessionCreate,
        1,
        2,
        "rejected".into(),
    )
    .expect("VoiceResponseEventArgs constructor");
    assert_eq!(response.type_, VoiceGatewayResponseType::SessionCreate);
    assert_eq!(response.return_code, 1);
    assert_eq!(response.status_code, 2);
    assert_eq!(response.message, "rejected");
}

#[test]
fn vivox_explicit_logging_and_position_defaults_match_source() {
    let logging =
        VoiceGatewayVoiceLoggingSettings::new().expect("VoiceLoggingSettings constructor");
    assert!(!logging.enabled);
    assert!(logging.folder.is_empty());
    assert_eq!(logging.file_name_prefix, "Connector");
    assert_eq!(logging.file_name_suffix, ".log");
    assert_eq!(logging.log_level, 0);

    let position = VoicePosition::new().expect("VoicePosition constructor");
    assert_eq!(position.position, Vector3d::default());
    assert_eq!(position.velocity, Vector3d::default());
    assert_eq!(position.at_orientation, Vector3d::default());
    assert_eq!(position.up_orientation, Vector3d::default());
    assert_eq!(position.left_orientation, Vector3d::default());
}
