backbone-mail 0.2.32

Odoo mail core port — message/notification/followers/activity/alias/sms queue (schema: messaging)
//! Version Compatibility Helpers
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Provides utilities for maintaining backward compatibility.

use super::version::ApiVersion;
use serde::{Deserialize, Serialize};

// =============================================================================
// Version Transform Trait
// =============================================================================

/// Trait for types that can be transformed between versions
pub trait VersionTransform {
    /// The type this transforms into for a specific version
    type Output;
    
    /// Transform this type to the representation for the given version
    fn to_version(&self, version: ApiVersion) -> Self::Output;
}

// =============================================================================
// Versioned Response Wrapper
// =============================================================================

/// Wrapper for versioned API responses
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VersionedResponse<T> {
    /// The API version used for this response
    pub api_version: String,
    /// The actual response data
    pub data: T,
    /// Deprecation warning if applicable
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deprecation_warning: Option<String>,
}

impl<T> VersionedResponse<T> {
    /// Create a new versioned response
    pub fn new(version: ApiVersion, data: T) -> Self {
        let deprecation_warning = if version.is_deprecated() {
            version.deprecation_message().map(|s| s.to_string())
        } else {
            None
        };
        
        Self {
            api_version: version.as_str().to_string(),
            data,
            deprecation_warning,
        }
    }
}

// =============================================================================
// Field Migration Helpers
// =============================================================================

/// Helper for renamed fields between versions
///
/// Use this to handle field renames gracefully.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RenamedField<T> {
    /// The new field name
    Current(T),
    /// The old field name (for backward compatibility)
    Legacy(T),
}

impl<T> RenamedField<T> {
    /// Get the inner value regardless of which variant it is
    pub fn into_inner(self) -> T {
        match self {
            Self::Current(v) | Self::Legacy(v) => v,
        }
    }
}

// =============================================================================
// Custom Compatibility Logic
// =============================================================================

// <<< CUSTOM COMPAT
// Add custom version compatibility transformations here.
// This section will be preserved during regeneration.
// >>> END CUSTOM COMPAT