use crate::database::universal_types::{UniversalTimestamp, UniversalUuid};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum StorageType {
Database,
Filesystem,
}
impl StorageType {
pub fn as_str(&self) -> &'static str {
match self {
StorageType::Database => "database",
StorageType::Filesystem => "filesystem",
}
}
}
impl std::str::FromStr for StorageType {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s.to_lowercase().as_str() {
"filesystem" => StorageType::Filesystem,
_ => StorageType::Database, })
}
}
impl std::fmt::Display for StorageType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkflowPackage {
pub id: UniversalUuid,
pub registry_id: UniversalUuid,
pub package_name: String,
pub version: String,
pub description: Option<String>,
pub author: Option<String>,
pub metadata: String,
pub storage_type: StorageType,
pub created_at: UniversalTimestamp,
pub updated_at: UniversalTimestamp,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewWorkflowPackage {
pub registry_id: UniversalUuid,
pub package_name: String,
pub version: String,
pub description: Option<String>,
pub author: Option<String>,
pub metadata: String,
pub storage_type: StorageType,
}
impl NewWorkflowPackage {
pub fn new(
registry_id: UniversalUuid,
package_name: String,
version: String,
description: Option<String>,
author: Option<String>,
metadata: String,
storage_type: StorageType,
) -> Self {
Self {
registry_id,
package_name,
version,
description,
author,
metadata,
storage_type,
}
}
}