backbone-mail 0.2.32

Odoo mail core port — message/notification/followers/activity/alias/sms queue (schema: messaging)
//! API Version Configuration for messaging
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This module defines API version constants and configuration.

use std::fmt;
use std::str::FromStr;

// =============================================================================
// API Versions
// =============================================================================

/// Supported API versions
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ApiVersion {
    /// Version 1
    V1,
}

/// Current/default API version
pub const CURRENT_VERSION: ApiVersion = ApiVersion::V1;

/// All supported API versions
pub const SUPPORTED_VERSIONS: &[ApiVersion] = &[
    ApiVersion::V1,
];

/// Version string constants
pub mod versions {
    pub const V1: &str = "v1";
}

impl ApiVersion {
    /// Get version as string (e.g., "v1")
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::V1 => "v1",
        }
    }

    /// Get major version number
    pub fn major(&self) -> u32 {
        match self {
            Self::V1 => 1,
        }
    }

    /// Check if this version is deprecated
    pub fn is_deprecated(&self) -> bool {
        match self {
            Self::V1 => false,
        }
    }

    /// Get deprecation message if deprecated
    pub fn deprecation_message(&self) -> Option<&'static str> {
        match self {
            Self::V1 => None,
        }
    }

    /// Get sunset date if deprecated
    pub fn sunset_date(&self) -> Option<&'static str> {
        match self {
            Self::V1 => None,
        }
    }
}

impl fmt::Display for ApiVersion {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl FromStr for ApiVersion {
    type Err = VersionParseError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "v1" | "1" => Ok(Self::V1),
            _ => Err(VersionParseError(s.to_string())),
        }
    }
}

/// Error when parsing an invalid version string
#[derive(Debug, Clone)]
pub struct VersionParseError(pub String);

impl std::error::Error for VersionParseError {}

impl fmt::Display for VersionParseError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "Invalid API version: '{}'", self.0)
    }
}