backbone-payroll 0.3.47

Payroll: salary structures, payroll runs and computed salary slips over effective-dated statutory tables, plus compensation changes
Documentation
//! Timestamps value object
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This is a DDD Value Object - immutable, no identity, equality by attributes.

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[cfg(feature = "openapi")]
use utoipa::ToSchema;

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
pub struct Timestamps {
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deleted_at: Option<DateTime<Utc>>,
}

impl Timestamps {
    /// Create a new Timestamps value object
    pub fn new(created_at: DateTime<Utc>, updated_at: DateTime<Utc>, deleted_at: Option<DateTime<Utc>>) -> Self {
        Self {
            created_at,
            updated_at,
            deleted_at,
        }
    }

    /// Create a builder for Timestamps
    pub fn builder() -> TimestampsBuilder {
        <TimestampsBuilder as Default>::default()
    }

}

/// Builder for Timestamps value object
#[derive(Debug, Clone, Default)]
pub struct TimestampsBuilder {
    created_at: Option<DateTime<Utc>>,
    updated_at: Option<DateTime<Utc>>,
    deleted_at: Option<DateTime<Utc>>,
}

impl TimestampsBuilder {
    /// Set the created_at field
    pub fn created_at(mut self, value: DateTime<Utc>) -> Self {
        self.created_at = Some(value);
        self
    }

    /// Set the updated_at field
    pub fn updated_at(mut self, value: DateTime<Utc>) -> Self {
        self.updated_at = Some(value);
        self
    }

    /// Set the deleted_at field
    pub fn deleted_at(mut self, value: DateTime<Utc>) -> Self {
        self.deleted_at = Some(value);
        self
    }

    /// Build the Timestamps value object
    pub fn build(self) -> Result<Timestamps, String> {
        let updated_at = self.updated_at.ok_or_else(|| "updated_at is required".to_string())?;

        let value = Timestamps {
            created_at: self.created_at.unwrap_or(chrono::Utc::now()),
            updated_at,
            deleted_at: self.deleted_at,
        };

        Ok(value)
    }

}