nomy-data-models 0.2.4

Data model definitions for Nomy wallet analysis data processing
Documentation
#![allow(clippy::too_many_arguments, unused_imports, non_camel_case_types)]
//! ServiceState model definition.
//!
//! This file is generated automatically from the Python SQLAlchemy model.
//! Do not edit this file manually.

use serde::{Deserialize, Serialize};

// Standard imports that may be needed
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde_json::Value as JsonValue;
use uuid::Uuid;

// Additional imports specific to this model
use crate::enums::ProcessingState;

/// Model for tracking service processing states.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServiceState {
    pub service_name: String,
    pub instance_id: String,
    pub service_state: String,
    pub error_message: Option<String>,
    pub service_result: Option<JsonValue>,
    pub id: Uuid,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
    pub created_by: Option<String>,
    pub updated_by: Option<String>,
}

impl ServiceState {
    /// Create a new ServiceState.
    pub fn new(
        service_name: String,
        instance_id: String,
        service_state: String,
        error_message: String,
        service_result: JsonValue,
        id: Uuid,
        created_at: DateTime<Utc>,
        updated_at: DateTime<Utc>,
        created_by: String,
        updated_by: String,
    ) -> Self {
        Self {
            service_name,
            instance_id,
            service_state,
            error_message: Some(error_message),
            service_result: Some(service_result),
            id,
            created_at,
            updated_at,
            created_by: Some(created_by),
            updated_by: Some(updated_by),
        }
    }

    /// Convert to a JSON string.
    pub fn to_json(&self) -> Result<String, serde_json::Error> {
        serde_json::to_string(self)
    }

    /// Convert from a JSON string.
    pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
        serde_json::from_str(json)
    }

    /// Convert to a dictionary-like structure.
    pub fn to_dict(&self) -> serde_json::Map<String, serde_json::Value> {
        let json = serde_json::to_value(self).unwrap_or(serde_json::Value::Null);
        if let serde_json::Value::Object(map) = json {
            map
        } else {
            serde_json::Map::new()
        }
    }
}