use crate::inspect::smp::save_load::*;

pub(in crate::inspect::smp) fn derive_loaded_region_collection_from_probe(
    probe: &SmpSaveRegionRecordTripletProbe,
) -> SmpLoadedRegionCollection {
    SmpLoadedRegionCollection {
        source_kind: probe.source_kind.clone(),
        semantic_family: "scenario-save-region-triplet-collection".to_string(),
        observed_entry_count: probe.record_count,
        entries: probe
            .entries
            .iter()
            .map(|entry| SmpLoadedRegionEntry {
                record_index: entry.record_index,
                name: entry.name.clone(),
                pre_name_prefix_len: entry.pre_name_prefix_len,
                policy_leading_f32_0: entry.policy_leading_f32_0,
                policy_leading_f32_1: entry.policy_leading_f32_1,
                policy_leading_f32_2: entry.policy_leading_f32_2,
                policy_reserved_dwords: entry.policy_reserved_dwords.clone(),
                policy_trailing_word: entry.policy_trailing_word,
                policy_trailing_word_hex: entry.policy_trailing_word_hex.clone(),
                profile_collection: entry.profile_collection.as_ref().map(|collection| {
                    SmpLoadedRegionProfileCollection {
                        direct_collection_flag: collection.direct_collection_flag,
                        entry_stride: collection.entry_stride,
                        live_id_bound: collection.live_id_bound,
                        live_record_count: collection.live_record_count,
                        trailing_padding_len: collection.trailing_padding_len,
                        entries: collection
                            .entries
                            .iter()
                            .map(|entry| SmpLoadedRegionProfileEntry {
                                entry_index: entry.entry_index,
                                name: entry.name.clone(),
                                trailing_weight_f32: entry.trailing_weight_f32,
                            })
                            .collect(),
                    }
                }),
            })
            .collect(),
    }
}

pub(in crate::inspect::smp) fn derive_loaded_region_fixed_row_run_summary_from_probe(
    probe: &SmpSaveRegionFixedRowRunCandidateProbe,
) -> SmpLoadedRegionFixedRowRunSummary {
    SmpLoadedRegionFixedRowRunSummary {
        source_kind: probe.source_kind.clone(),
        semantic_family: "scenario-save-region-fixed-row-run-summary".to_string(),
        target_row_count: probe.target_row_count,
        target_row_stride: probe.target_row_stride,
        target_row_stride_hex: probe.target_row_stride_hex.clone(),
        candidates: probe.candidates.clone(),
    }
}
