// Downstream capture/decoder compatibility contracts.
//
// Scope: lock down the supported RCT capture modes and H.264 decoder hardware
// matrix used for server-to-client downstream video.
// Targets: `common/src/eye_source.rs`, `client/src/output/video/monitor_window.rs`,
// and `server/src/video/eye_capture.rs`.
// Why: downstream transport is H.264 pass-through from the capture cards; mode
// or decoder drift can increase lag or break display on a fresh install.

use lesavka_common::eye_source::{
    EyeSourceMode, eye_source_mode_for_request, native_eye_source_modes,
};

const CLIENT_MONITOR: &str = include_str!("../../../../client/src/output/video/monitor_window.rs");
const SERVER_EYE_CAPTURE: &str = include_str!("../../../../server/src/video/eye_capture.rs");

#[test]
fn downstream_native_modes_remain_1080p60_and_720p60() {
    assert_eq!(
        native_eye_source_modes(),
        &[
            EyeSourceMode {
                width: 1920,
                height: 1080,
                fps: 60,
            },
            EyeSourceMode {
                width: 1280,
                height: 720,
                fps: 60,
            },
        ]
    );
    assert_eq!(eye_source_mode_for_request(1920, 1080).fps, 60);
    assert_eq!(eye_source_mode_for_request(1280, 720).fps, 60);
}

#[test]
fn client_decoder_matrix_requires_hardware_with_lab_fallback_explicit() {
    for decoder in [
        "nvh264dec",
        "nvh264sldec",
        "vulkanh264dec",
        "vah264dec",
        "vaapih264dec",
        "v4l2h264dec",
        "v4l2slh264dec",
        "LESAVKA_ALLOW_SOFTWARE_VIDEO",
        "hardware H.264 decoder required",
    ] {
        assert!(
            CLIENT_MONITOR.contains(decoder),
            "client decoder matrix should contain {decoder}"
        );
    }
}

#[test]
fn server_downstream_capture_stays_h264_annex_b_passthrough_for_real_cards() {
    for marker in [
        "video/x-h264,width={},height={}",
        "h264parse disable-passthrough=true config-interval=-1",
        "video/x-h264,stream-format=byte-stream,alignment=au",
        "server_encoder_label = if use_test_src",
        "\"source-pass-through\".to_string()",
    ] {
        assert!(
            SERVER_EYE_CAPTURE.contains(marker),
            "server capture compatibility should preserve marker {marker}"
        );
    }
}
