use serde::{Deserialize, Serialize};
use std::time::Duration;
use crate::task_id::TaskId;
#[derive(Debug, Serialize, Deserialize,Clone)]
pub struct RabbitResult {
pub logging_level: LoggingLevel,
pub billing_type: BillingType,
pub task_result: TaskResult,
}
impl RabbitResult {
pub fn to_bytes(&self) -> Vec<u8> {
serde_json::to_vec(self).unwrap()
}
}
impl RabbitResult {
pub fn get_routing_prefix(&self) -> String {
self.logging_level.to_string() + "." + &self.billing_type.to_string()
}
}
#[derive(Debug, Serialize, Deserialize,Clone)]
pub struct TaskResult {
pub task_id: TaskId,
pub task_type: String,
pub engine_metadata: EngineMetadata,
pub data: serde_json::Value,
}
#[derive(Debug, Serialize, Deserialize,Clone)]
pub struct EngineMetadata {
pub engine_id: String,
pub time_taken: Duration,
}
#[derive(Debug, Serialize, Deserialize,Clone)]
pub enum LoggingLevel {
Unlogged,
Debug,
Info,
Warning,
Error,
}
impl ToString for LoggingLevel {
fn to_string(&self) -> String {
match self {
LoggingLevel::Unlogged => "Unlogged".to_string(),
LoggingLevel::Debug => "Debug".to_string(),
LoggingLevel::Info => "Info".to_string(),
LoggingLevel::Warning => "Warning".to_string(),
LoggingLevel::Error => "Error".to_string(),
}
}
}
#[derive(Debug, Serialize, Deserialize,Clone)]
pub enum BillingType {
Prepaid,
Postpaid,
NotBilled,
}
impl ToString for BillingType {
fn to_string(&self) -> String {
match self {
BillingType::Prepaid => "Prepaid".to_string(),
BillingType::Postpaid => "Postpaid".to_string(),
BillingType::NotBilled => "NotBilled".to_string(),
}
}
}