use crate::inspect::smp::structures::*;

pub(in crate::inspect::smp) fn derive_loaded_placed_structure_dynamic_side_buffer_summary(
    probe: &SmpSavePlacedStructureDynamicSideBufferProbe,
    alignment: Option<&SmpSavePlacedStructureDynamicSideBufferAlignmentProbe>,
) -> SmpLoadedPlacedStructureDynamicSideBufferSummary {
    SmpLoadedPlacedStructureDynamicSideBufferSummary {
        source_kind: probe.source_kind.clone(),
        semantic_family: "scenario-save-placed-structure-dynamic-side-buffer-summary".to_string(),
        observed_entry_count: probe.live_record_count,
        owner_shared_dword_hex: probe.owner_shared_dword_hex.clone(),
        unique_embedded_name_pair_count: probe.unique_embedded_name_pair_count,
        decoded_embedded_name_row_count: probe.decoded_embedded_name_row_count,
        first_prefix_leading_dword_hex: probe.prefix_leading_dword_hex.clone(),
        first_prefix_trailing_word_hex: probe.prefix_trailing_word_hex.clone(),
        first_prefix_separator_byte_hex: probe.prefix_separator_byte_hex.clone(),
        triplet_alignment_overlap_count: alignment
            .map(|alignment| alignment.overlapping_name_pair_count)
            .unwrap_or_default(),
        triplet_alignment_side_buffer_only_name_pair_count: alignment
            .map(|alignment| {
                alignment
                    .unique_side_buffer_name_pair_count
                    .saturating_sub(alignment.overlapping_name_pair_count)
            })
            .unwrap_or_default(),
        compact_prefix_pattern_summaries: probe.compact_prefix_pattern_summaries.clone(),
        name_pair_summaries: probe.name_pair_summaries.clone(),
    }
}
