use crate::data_type::DataType; use crate::data_value::DataValue; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use thiserror::Error; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CommandParameterDefinition { pub name: String, pub data_type: DataType, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CommandDefinition { pub name: String, pub parameters: Vec, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CommandHeader { pub timestamp: DateTime, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Command { #[serde(flatten)] pub header: CommandHeader, pub parameters: HashMap, } #[derive(Debug, PartialEq, Eq, Error)] pub enum IntoCommandDefinitionError { #[error("Parameter Missing: {0}")] ParameterMissing(String), #[error("Mismatched Type for {parameter}. {expected:?} expected")] MismatchedType { parameter: String, expected: DataType, }, } pub trait IntoCommandDefinition: Sized { fn create(name: String) -> CommandDefinition; fn parse(command: Command) -> Result; }