nomy_data_models/models/
service_state.rs

1#![allow(clippy::too_many_arguments, unused_imports, non_camel_case_types)]
2//! ServiceState model definition.
3//!
4//! This file is generated automatically from the Python SQLAlchemy model.
5//! Do not edit this file manually.
6
7use serde::{Deserialize, Serialize};
8
9// Standard imports that may be needed
10use chrono::{DateTime, Utc};
11use rust_decimal::Decimal;
12use serde_json::Value as JsonValue;
13use uuid::Uuid;
14
15// Additional imports specific to this model
16use crate::enums::ProcessingState;
17
18/// Model for tracking service processing states.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct ServiceState {
21    pub service_name: String,
22    pub instance_id: String,
23    pub service_state: String,
24    pub error_message: Option<String>,
25    pub service_result: Option<JsonValue>,
26    pub id: Uuid,
27    pub created_at: DateTime<Utc>,
28    pub updated_at: DateTime<Utc>,
29    pub created_by: Option<String>,
30    pub updated_by: Option<String>,
31}
32
33impl ServiceState {
34    /// Create a new ServiceState.
35    pub fn new(
36        service_name: String,
37        instance_id: String,
38        service_state: String,
39        error_message: String,
40        service_result: JsonValue,
41        id: Uuid,
42        created_at: DateTime<Utc>,
43        updated_at: DateTime<Utc>,
44        created_by: String,
45        updated_by: String,
46    ) -> Self {
47        Self {
48            service_name,
49            instance_id,
50            service_state,
51            error_message: Some(error_message),
52            service_result: Some(service_result),
53            id,
54            created_at,
55            updated_at,
56            created_by: Some(created_by),
57            updated_by: Some(updated_by),
58        }
59    }
60
61    /// Convert to a JSON string.
62    pub fn to_json(&self) -> Result<String, serde_json::Error> {
63        serde_json::to_string(self)
64    }
65
66    /// Convert from a JSON string.
67    pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
68        serde_json::from_str(json)
69    }
70
71    /// Convert to a dictionary-like structure.
72    pub fn to_dict(&self) -> serde_json::Map<String, serde_json::Value> {
73        let json = serde_json::to_value(self).unwrap_or(serde_json::Value::Null);
74        if let serde_json::Value::Object(map) = json {
75            map
76        } else {
77            serde_json::Map::new()
78        }
79    }
80}