use super::DynamicConfig;
use core::time::Duration;
#[ derive( Debug, Clone ) ]
pub struct RollbackAnalysis
{
pub target_config : DynamicConfig,
pub changed_fields : Vec< String >,
pub impact_level : RollbackImpact,
pub warnings : Vec< String >,
pub estimated_duration : Duration,
pub is_safe : bool,
}
#[ derive( Debug, Clone, PartialEq, Eq, PartialOrd, Ord ) ]
pub enum RollbackImpact
{
Low,
Medium,
High,
Critical,
}
impl RollbackAnalysis
{
pub fn analyze_rollback( current_config : &DynamicConfig, target_config : &DynamicConfig ) -> Self
{
let mut changed_fields = Vec::new();
let mut warnings = Vec::new();
let mut impact_level = RollbackImpact::Low;
if current_config.base_url != target_config.base_url
{
changed_fields.push( "base_url".to_string() );
warnings.push( "Base URL change may affect connectivity".to_string() );
impact_level = RollbackImpact::High;
}
if current_config.timeout != target_config.timeout
{
changed_fields.push( "timeout".to_string() );
if target_config.timeout < Duration::from_secs( 5 )
{
warnings.push( "Very short timeout may cause request failures".to_string() );
impact_level = std::cmp::max( impact_level, RollbackImpact::Medium );
}
}
if current_config.retry_attempts != target_config.retry_attempts
{
changed_fields.push( "retry_attempts".to_string() );
if target_config.retry_attempts == 0
{
warnings.push( "Zero retry attempts may reduce reliability".to_string() );
impact_level = std::cmp::max( impact_level, RollbackImpact::Medium );
}
}
if current_config.enable_jitter != target_config.enable_jitter
{
changed_fields.push( "enable_jitter".to_string() );
}
if current_config.max_retry_delay != target_config.max_retry_delay
{
changed_fields.push( "max_retry_delay".to_string() );
}
if current_config.base_retry_delay != target_config.base_retry_delay
{
changed_fields.push( "base_retry_delay".to_string() );
}
if current_config.backoff_multiplier != target_config.backoff_multiplier
{
changed_fields.push( "backoff_multiplier".to_string() );
}
if current_config.source_priority != target_config.source_priority
{
changed_fields.push( "source_priority".to_string() );
}
if current_config.tags != target_config.tags
{
changed_fields.push( "tags".to_string() );
}
let is_safe = impact_level != RollbackImpact::Critical && warnings.len() < 3;
let estimated_duration = match impact_level
{
RollbackImpact::Low => Duration::from_millis( 100 ),
RollbackImpact::Medium => Duration::from_millis( 500 ),
RollbackImpact::High => Duration::from_secs( 1 ),
RollbackImpact::Critical => Duration::from_secs( 3 ),
};
Self {
target_config : target_config.clone(),
changed_fields,
impact_level,
warnings,
estimated_duration,
is_safe,
}
}
}