use crate::inspect::smp::services::*;

pub(super) struct InfrastructureFamilyScan {
    pub(super) bridge_like_name_pair_count: usize,
    pub(super) tunnel_like_name_pair_count: usize,
    pub(super) track_cap_like_name_pair_count: usize,
    pub(super) st_only_name_pair_corpus: bool,
}

pub(super) fn analyze_infrastructure_name_pairs(
    analysis: &SmpSaveCompanyChairmanAnalysisReport,
) -> InfrastructureFamilyScan {
    let side_buffer = analysis.placed_structure_dynamic_side_buffer.as_ref();
    let name_pair_summaries = side_buffer
        .map(|probe| probe.name_pair_summaries.as_slice())
        .unwrap_or(&[]);
    let bridge_like_name_pair_count = name_pair_summaries
        .iter()
        .filter(|summary| summary.primary_name.contains("Bridge"))
        .count();
    let tunnel_like_name_pair_count = name_pair_summaries
        .iter()
        .filter(|summary| summary.primary_name.contains("Tunnel"))
        .count();
    let track_cap_like_name_pair_count = name_pair_summaries
        .iter()
        .filter(|summary| summary.primary_name.contains("TrackCap"))
        .count();
    let st_only_name_pair_corpus = !name_pair_summaries.is_empty()
        && name_pair_summaries
            .iter()
            .all(|summary| summary.primary_name.contains("ST"))
        && !name_pair_summaries
            .iter()
            .any(|summary| summary.primary_name.contains("DT"));

    InfrastructureFamilyScan {
        bridge_like_name_pair_count,
        tunnel_like_name_pair_count,
        track_cap_like_name_pair_count,
        st_only_name_pair_corpus,
    }
}
