use domain::models::Channel; use domain::{DomainError, DomainResult}; use super::commands::RestoreSnapshotCommand; use super::deps::ConfigSnapshotDeps; pub async fn execute( deps: &ConfigSnapshotDeps, cmd: RestoreSnapshotCommand, ) -> DomainResult { let snapshot = deps .channel_query .get_config_snapshot(cmd.channel_id, cmd.snapshot_id) .await? .ok_or(DomainError::ValidationError(format!( "Snapshot {} not found", cmd.snapshot_id )))?; let mut channel = deps .channel_query .find_by_id(cmd.channel_id) .await? .ok_or(DomainError::ChannelNotFound(cmd.channel_id))?; deps.channel_command .save_config_snapshot(cmd.channel_id, channel.schedule_config(), None) .await?; channel.set_schedule_config(snapshot.config().clone()); deps.channel_command.save(&channel).await?; Ok(channel) }