use std::path::Path; use crate::error::AppError; use crate::models::MissionPlan; pub fn write_mission(path: &Path, mission: &MissionPlan) -> Result<(), AppError> { // Clear computed timing fields before saving let mut cleaned = mission.clone(); for task in &mut cleaned.tasks { task.duration_minutes = 0.0; task.estimated_duration_minutes = 0.0; task.start_time = Some("".to_string()); task.end_time = Some("".to_string()); for sub in &mut task.sub_tasks { sub.duration_minutes = 0.0; sub.estimated_duration_minutes = 0.0; sub.start_time = Some("".to_string()); sub.end_time = Some("".to_string()); if sub.capture_interval_seconds.is_none() { sub.capture_interval_seconds = Some(0); } if sub.exposure_time.is_none() { sub.exposure_time = Some(0); } if sub.frame_rate.is_none() { sub.frame_rate = Some(0); } } } let content = serde_json::to_string_pretty(&cleaned)?; let content = content .replace("\"durationMinutes\": 0.0", "\"durationMinutes\": \"\"") .replace("\"estimatedDurationMinutes\": 0.0", "\"estimatedDurationMinutes\": \"\""); std::fs::write(path, content)?; Ok(()) }