righvalor 0.1.0

RighValor: AI Infrastructure and Applications Framework for the Far Edge
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// Simple string-based service identifier used by API and tasks
/// Examples: "righ.device_classification", "common.utility"
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)]
pub struct ValorServiceId(pub String);

impl ValorServiceId {
    // Predefined service ID constants
    pub const RIGH_DEVICE_CLASSIFICATION: &'static str = "righ.device_classification";
    pub const COMMON_CMD: &'static str = "common.cmd";

    /// Create a new service ID for Righ device classification
    #[allow(unused)]
    pub fn righ_device_classification() -> Self {
        Self(Self::RIGH_DEVICE_CLASSIFICATION.to_string())
    }

    /// Create a new service ID for common command service
    #[allow(unused)]
    pub fn common_cmd() -> Self {
        Self(Self::COMMON_CMD.to_string())
    }

    /// Get the inner string value
    #[allow(unused)]
    pub fn as_str(&self) -> &str {
        &self.0
    }
}

impl<T: Into<String>> From<T> for ValorServiceId {
    fn from(value: T) -> Self {
        Self(value.into())
    }
}

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

impl AsRef<str> for ValorServiceId {
    fn as_ref(&self) -> &str {
        &self.0
    }
}