//! Phase 33-17: Merge Result Data Structure
//!
//! Contains all information needed for exit PHI construction.
//!
//! Extracted from instruction_rewriter.rs (lines 71-81) for single responsibility.

use crate::mir::{BasicBlockId, ValueId};
use std::collections::BTreeMap;

/// Phase 33-13: Return type for merge_and_rewrite
///
/// Contains all information needed for exit PHI construction.
pub struct MergeResult {
    /// The ID of the exit block where all Returns jump to
    pub exit_block_id: BasicBlockId,
    /// Vec of (from_block, return_value) for expr result PHI generation
    pub exit_phi_inputs: Vec<(BasicBlockId, ValueId)>,
    /// Map of carrier_name → Vec of (from_block, exit_value) for carrier PHI generation
    pub carrier_inputs: BTreeMap<String, Vec<(BasicBlockId, ValueId)>>,
}

impl MergeResult {
    /// Create a new MergeResult with empty inputs
    #[allow(dead_code)]
    pub fn new(exit_block_id: BasicBlockId) -> Self {
        Self {
            exit_block_id,
            exit_phi_inputs: Vec::new(),
            carrier_inputs: BTreeMap::new(),
        }
    }

    /// Add an exit PHI input
    #[allow(dead_code)]
    pub fn add_exit_phi_input(&mut self, from_block: BasicBlockId, value: ValueId) {
        self.exit_phi_inputs.push((from_block, value));
    }

    /// Add a carrier input
    #[allow(dead_code)]
    pub fn add_carrier_input(
        &mut self,
        carrier_name: String,
        from_block: BasicBlockId,
        value: ValueId,
    ) {
        self.carrier_inputs
            .entry(carrier_name)
            .or_insert_with(Vec::new)
            .push((from_block, value));
    }
}
