use std::path::PathBuf;
use anyhow::{anyhow, Result};
use righ_dm_rs::RighVersion;
use serde::{Deserialize, Serialize};
use crate::{
runtime::ValorRuntimeEngine,
service::{ValorServiceEntity, ValorServiceId},
};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValorRighDeviceClassificationService {
runtime: ValorRuntimeEngine,
version: RighVersion,
metadata: Vec<u8>,
model_path: Option<PathBuf>,
}
impl ValorRighDeviceClassificationService {
#[must_use]
pub fn builder() -> ValorRighDeviceClassificationServiceBuilder {
ValorRighDeviceClassificationServiceBuilder::default()
}
}
#[derive(Debug, Default, Clone)]
pub struct ValorRighDeviceClassificationServiceBuilder {
runtime: Option<ValorRuntimeEngine>,
version: Option<RighVersion>,
metadata: Option<Vec<u8>>,
model_path: Option<PathBuf>,
}
impl ValorRighDeviceClassificationServiceBuilder {
pub fn runtime(mut self, runtime: ValorRuntimeEngine) -> Self {
self.runtime = Some(runtime);
self
}
pub fn version(mut self, version: RighVersion) -> Self {
self.version = Some(version);
self
}
pub fn metadata<M: Into<Vec<u8>>>(mut self, metadata: M) -> Self {
self.metadata = Some(metadata.into());
self
}
pub fn model_path<P: Into<PathBuf>>(mut self, model_path: P) -> Self {
self.model_path = Some(model_path.into());
self
}
pub fn build(self) -> Result<ValorRighDeviceClassificationService> {
let runtime = self.runtime.ok_or_else(|| anyhow!("runtime is required"))?;
let version = self.version.ok_or_else(|| anyhow!("version is required"))?;
let metadata = self.metadata.unwrap_or_default();
let model_path: Option<PathBuf> = self.model_path;
Ok(ValorRighDeviceClassificationService {
runtime,
version,
metadata,
model_path,
})
}
}
impl ValorServiceEntity for ValorRighDeviceClassificationService {
fn service_id(&self) -> ValorServiceId {
ValorServiceId::righ_device_classification()
}
fn runtime(&self) -> ValorRuntimeEngine {
self.runtime.clone()
}
fn version(&self) -> RighVersion {
self.version.clone()
}
fn metadata(&self) -> Option<&[u8]> {
Some(&self.metadata)
}
fn model_path(&self) -> Option<&PathBuf> {
self.model_path.as_ref()
}
}