use super::super::peer_site::PeerSiteTraceInputs;

pub(super) fn push_save_side_payload_notes(
    notes: &mut Vec<String>,
    peer_site: &PeerSiteTraceInputs,
) {
    let payload_summaries = &peer_site.peer_site_selector_candidate_saved_payload_summaries;
    let payload_delta_summaries =
        &peer_site.peer_site_selector_candidate_saved_payload_delta_summaries;
    let footer_padding_summaries =
        &peer_site.peer_site_selector_candidate_saved_footer_padding_summaries;
    let companion_byte_summaries =
        &peer_site.peer_site_selector_candidate_saved_companion_byte_summaries;
    let policy_trailing_word_summaries =
        &peer_site.peer_site_selector_candidate_saved_policy_trailing_word_summaries;
    let nonzero_name_pair_summaries =
        &peer_site.peer_site_selector_candidate_saved_nonzero_companion_name_pair_summaries;
    let building_family_overlap_summaries = &peer_site
        .peer_site_selector_candidate_saved_nonzero_companion_building_family_overlap_summaries;
    let building_family_residue_summaries = &peer_site
        .peer_site_selector_candidate_saved_nonzero_companion_building_family_residue_summaries;

    if !payload_summaries.is_empty() {
        notes.push(format!(
            "The periodic-company trace now also carries a compact save-side summary of the tagged 0x5dc1 placed-structure profile payload/status pairs already parsed from the 0x36b1 triplet seam; dominant current pair is {} / {} x{}, dominant adjacent payload delta is {:?}, dominant post-secondary byte is {:?}, dominant fixed-policy trailing word is {:?}, and dominant pre-footer padding len is {:?}.",
            payload_summaries[0].profile_payload_dword_hex,
            payload_summaries[0].profile_status_kind,
            payload_summaries[0].count,
            payload_delta_summaries.first().map(|entry| entry.delta_hex.as_str()),
            companion_byte_summaries
                .first()
                .map(|entry| entry.companion_byte_hex.as_str()),
            policy_trailing_word_summaries
                .first()
                .map(|entry| entry.policy_trailing_word_hex.as_str()),
            footer_padding_summaries.first().map(|entry| entry.padding_len)
        ));
    }
    if !nonzero_name_pair_summaries.is_empty() {
        let dominant_nonzero_companion = &nonzero_name_pair_summaries[0];
        notes.push(format!(
            "The nonzero 0x5dc1 post-secondary byte residue is now narrower too: the trace exposes exact saved name pairs for nonzero-byte rows, and the current leading pair is {} / {} with byte {} x{}. The same atlas-backed owner strip already restores the repeated primary and secondary payload strings into [owner+0x23e] and [owner+0x242], so this byte should now be treated as a separate discriminator after the secondary string, not as the [owner+0x242] field itself. On grounded saves the exposed nonzero sample set is dominated by industry-like names rather than stations, maintenance, or residential rows, which makes the byte a stronger acquisition-side discriminator candidate than the monotone payload dword.",
            dominant_nonzero_companion.primary_name,
            dominant_nonzero_companion.secondary_name,
            dominant_nonzero_companion.companion_byte_hex,
            dominant_nonzero_companion.count
        ));
    }
    if !building_family_overlap_summaries.is_empty() {
        let dominant_overlap = &building_family_overlap_summaries[0];
        notes.push(format!(
            "The same nonzero 0x5dc1 name-pair residue now bridges directly into the recovered stock Tier-2 building family too: the leading overlapping saved pair is {} / {} with byte {} x{}, and it matches the checked-in nonzero stock `.bty` header family (`dword_0xbb = 0x000001f4`) rather than the zero-valued station or maintenance/service families. That makes the acquisition-side discriminator and the Tier-2 banked-clone frontier a shared narrower industrial/commercial subset question, not two separate broad mysteries.",
            dominant_overlap.primary_name,
            dominant_overlap.secondary_name,
            dominant_overlap.companion_byte_hex,
            dominant_overlap.count
        ));
    }
    if !building_family_residue_summaries.is_empty() {
        let dominant_residue = &building_family_residue_summaries[0];
        notes.push(format!(
            "The same trace now keeps the explicit non-overlap residue visible too: the leading saved pair still outside that recovered nonzero stock `.bty` family is {} / {} with byte {} x{}. That keeps the current Tier-2/source-selection queue honest: part of the peer-site nonzero residue now maps cleanly onto the recovered 0x000001f4 industrial/commercial family, but the remaining residue still needs a broader stock-header or later chooser-side explanation rather than being silently folded into the overlap set.",
            dominant_residue.primary_name,
            dominant_residue.secondary_name,
            dominant_residue.companion_byte_hex,
            dominant_residue.count
        ));
    }
    notes.push(
        "Direct disassembly now also separates the narrower peer-class gate from that payload residue: 0x0047fd50 resolves the linked peer through [site+0x04], reads candidate class byte [candidate+0x8c], and returns true only for values 0/1/2 while rejecting 3/4 and above. That means the newly isolated post-secondary byte is not the already-grounded station-or-transit class gate itself; it remains a separate saved discriminator above the restored name-pair payload.".to_string(),
    );
    if let (Some(dominant_companion), Some(dominant_trailing_word)) = (
        companion_byte_summaries.first(),
        policy_trailing_word_summaries.first(),
    ) {
        notes.push(format!(
            "The same focused 0x36b1 triplet probe now also keeps the fixed-policy trailing word narrow at {} x{} while the profile side stays dominated by companion byte {} and payload/status pair {} / {}. Together that keeps the checked-in triplet seam looking like local structure/profile state rather than the missing acquisition owner-company lane [site+0x276] or cached tri-lane [site+0x310/+0x338/+0x360].",
            dominant_trailing_word.policy_trailing_word_hex,
            dominant_trailing_word.count,
            dominant_companion.companion_byte_hex,
            payload_summaries[0].profile_payload_dword_hex,
            payload_summaries[0].profile_status_kind,
        ));
    }
}
