use super::super::types::{ExecutorResult, PreprocessedData, RawOutputs};
use crate::execution::template::PipelineStage;
use crate::runtime_adapter::{AdapterError, ModelRuntime};
use ndarray::ArrayD;
use std::collections::HashMap;
use std::path::Path;
pub fn execute_single_shot_stage(
stage: &PipelineStage,
current_data: &PreprocessedData,
_stage_outputs: &HashMap<String, HashMap<String, ArrayD<f32>>>,
runtime: &mut dyn ModelRuntime,
base_path: &str,
) -> ExecutorResult<HashMap<String, ArrayD<f32>>> {
let model_full_path = Path::new(base_path).join(&stage.model_file);
runtime
.load(&model_full_path)
.map_err(|e| AdapterError::RuntimeError(format!("Stage load failed: {}", e)))?;
let input_envelope = current_data.to_envelope()?;
let output_envelope = runtime.execute(&input_envelope)?;
let raw_outputs = RawOutputs::from_envelope(&output_envelope)?;
if let RawOutputs::TensorMap(map) = raw_outputs {
Ok(map)
} else {
Err(AdapterError::RuntimeError(
"Stage execution did not return tensors".to_string(),
))
}
}