// Performance budget model for optional Opus upstream audio transport.
//
// Scope: compare transport payload budgets without invoking hardware or live
// network paths.
// Targets: `common/src/audio_transport.rs`.
// Why: Opus is only worth exploring if it materially reduces upstream bytes
// while preserving the 20 ms audio cadence needed for sync and freshness.

use lesavka_common::audio_transport::AudioTransportProfile;

#[test]
fn opus_transport_budget_is_small_enough_to_be_worth_testing() {
    let pcm = AudioTransportProfile::pcm_s16le();
    let opus = AudioTransportProfile::opus_voice();

    assert_eq!(pcm.frame_duration_us, opus.frame_duration_us);
    assert_eq!(pcm.sample_rate, opus.sample_rate);
    assert_eq!(pcm.channels, opus.channels);
    assert!(
        opus.expected_payload_bytes() <= 260,
        "96 kbps, 20 ms Opus packets should stay near 240 bytes"
    );
    assert!(
        pcm.expected_payload_bytes() >= opus.expected_payload_bytes() * 12,
        "Opus should remove over 90% of raw PCM uplink byte pressure"
    );
}

#[test]
fn opus_latency_budget_keeps_packetization_below_voice_call_thresholds() {
    let opus = AudioTransportProfile::opus_voice();

    assert!(
        opus.frame_duration_us <= 20_000,
        "Opus frames longer than 20 ms would eat into the upstream freshness budget"
    );
    assert_eq!(
        1_000_000 / opus.frame_duration_us,
        50,
        "20 ms Opus frames should produce 50 audio opportunities per second"
    );
}
