#[cfg(not(coverage))]
fn initial_camera_profile_id_from_env() -> Option<String> {
    let width = std::env::var("LESAVKA_CAM_WIDTH").ok()?;
    let height = std::env::var("LESAVKA_CAM_HEIGHT").ok()?;
    let fps = std::env::var("LESAVKA_CAM_FPS").ok()?;
    Some(format!("{width}x{height}@{fps}"))
}

#[cfg(not(coverage))]
fn parse_camera_profile_id(raw: &str) -> Option<(u32, u32, u32)> {
    let (size, fps) = raw.split_once('@')?;
    let (width, height) = size.split_once('x')?;
    let width = width.parse().ok()?;
    let height = height.parse().ok()?;
    let fps = fps.parse().ok()?;
    (width > 0 && height > 0 && fps > 0).then_some((width, height, fps))
}

#[cfg(not(coverage))]
/// Keeps `abort_if_required_media_source_failed` explicit because it sits on the live uplink path, where stale media must be dropped instead of queued into latency.
/// Inputs are the typed parameters; output is the return value or side effect.
fn abort_if_required_media_source_failed(
    kind: &str,
    icon: &str,
    source: Option<&str>,
    err: &dyn std::fmt::Display,
) {
    if !explicit_media_sources_required() || source.is_none_or(|source| source.trim().is_empty()) {
        return;
    }
    let source = source.expect("checked source presence");
    error!(
        "{icon} required {kind} source '{source}' failed to start; aborting client because LESAVKA_REQUIRE_EXPLICIT_MEDIA_SOURCES=1: {err}"
    );
    eprintln!(
        "{icon} required {kind} source '{source}' failed to start; aborting client because LESAVKA_REQUIRE_EXPLICIT_MEDIA_SOURCES=1: {err}"
    );
    std::process::exit(2);
}

#[cfg(not(coverage))]
fn explicit_media_sources_required() -> bool {
    std::env::var("LESAVKA_REQUIRE_EXPLICIT_MEDIA_SOURCES")
        .ok()
        .is_some_and(|value| {
            let value = value.trim();
            value == "1"
                || value.eq_ignore_ascii_case("true")
                || value.eq_ignore_ascii_case("yes")
                || value.eq_ignore_ascii_case("on")
        })
}
