righvalor 0.1.0

RighValor: AI Infrastructure and Applications Framework for the Far Edge
use std::path::PathBuf;

use righ_dm_rs::RighVersion;
use serde::{Deserialize, Serialize};

use crate::{
    runtime::ValorRuntimeEngine,
    service::{ValorServiceEntity, ValorServiceId},
};

/// # Valor Common Command Service
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValorCommonCmdService {
    runtime: ValorRuntimeEngine,
    version: RighVersion,
    command: String,
    args: Vec<String>,
}

impl ValorCommonCmdService {
    #[allow(unused)]
    pub fn command(&self) -> &str {
        &self.command
    }

    #[allow(unused)]
    pub fn args(&self) -> &[String] {
        &self.args
    }
}

impl ValorCommonCmdService {
    /// Create a new builder for `ValorCommonCmdService`.
    #[must_use]
    pub fn builder() -> ValorCommonCmdServiceBuilder {
        ValorCommonCmdServiceBuilder::default()
    }
}

/// Builder for ValorCommonCmdService.
#[derive(Debug, Default, Clone)]
pub struct ValorCommonCmdServiceBuilder {
    runtime: Option<ValorRuntimeEngine>,
    version: Option<RighVersion>,
    command: Option<String>,
    args: Option<Vec<String>>,
}

impl ValorCommonCmdServiceBuilder {
    /// Set the runtime engine (optional).
    pub fn runtime(mut self, runtime: ValorRuntimeEngine) -> Self {
        self.runtime = Some(runtime);
        self
    }

    /// Set the version (optional).
    pub fn version(mut self, version: RighVersion) -> Self {
        self.version = Some(version);
        self
    }

    /// Set the command (required).
    pub fn command<S: Into<String>>(mut self, command: S) -> Self {
        self.command = Some(command.into());
        self
    }

    /// Set the command arguments (optional, default empty).
    #[allow(unused)]
    pub fn args<A: Into<Vec<String>>>(mut self, args: A) -> Self {
        self.args = Some(args.into());
        self
    }

    /// Build the service, validating required fields.
    pub fn build(self) -> anyhow::Result<ValorCommonCmdService> {
        let runtime = self.runtime.unwrap_or(ValorRuntimeEngine::Cmd);
        let version = self.version.unwrap_or_default();
        let command = self.command.unwrap_or_default();
        let args = self.args.unwrap_or_default();

        Ok(ValorCommonCmdService {
            runtime,
            version,
            command,
            args,
        })
    }
}

impl ValorServiceEntity for ValorCommonCmdService {
    fn service_id(&self) -> ValorServiceId {
        ValorServiceId::common_cmd()
    }

    fn runtime(&self) -> ValorRuntimeEngine {
        self.runtime.clone()
    }

    fn version(&self) -> RighVersion {
        self.version.clone()
    }

    fn metadata(&self) -> Option<&[u8]> {
        None
    }

    fn model_path(&self) -> Option<&PathBuf> {
        None
    }
}