//! MergeStepBox (Phase 106)
//!
//! Responsibility: run JoinIR conversion pipeline (JoinIR → MIR merge) and return void.

use crate::mir::builder::MirBuilder;
use crate::mir::ValueId;
use crate::mir::join_ir::lowering::inline_boundary::JoinInlineBoundary;

pub(crate) struct MergeStepBox;

impl MergeStepBox {
    pub(crate) fn merge(
        builder: &mut MirBuilder,
        join_module: crate::mir::join_ir::JoinModule,
        boundary: JoinInlineBoundary,
        debug: bool,
    ) -> Result<Option<ValueId>, String> {
        use crate::mir::builder::emission::constant::emit_void;
        use super::super::conversion_pipeline::JoinIRConversionPipeline;

        let _ = JoinIRConversionPipeline::execute(builder, join_module, Some(&boundary), "pattern2", debug)?;

        let void_val = emit_void(builder);
        super::super::super::trace::trace().debug("pattern2", &format!("Loop complete, returning Void {:?}", void_val));
        Ok(Some(void_val))
    }
}
