quickbooks-types 0.1.2

Type definitions for QuickBooks Online API
Documentation
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

use crate::{
    common::{MetaData, NtRef},
    QBCreatable, QBFullUpdatable, QBReadable,
};

#[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)]
#[serde(rename_all = "PascalCase", default)]
#[cfg_attr(
    feature = "builder",
    derive(Builder),
    builder(default, build_fn(error = "QBTypeError"), setter(into, strip_option))
)]
/// Class
///
/// Represents a classification or category that can be applied to transactions and entities in `QuickBooks` Online. Classes allow for tracking and reporting on different segments of a business, such as departments, locations, or product lines. A class can have a hierarchical structure with parent and child classes.
///
/// API reference:
/// <https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/class>
pub struct Class {
    /// The unique ID of the entity
    pub id: Option<String>,
    /// The unique sync token of the entity, used for concurrency control
    pub sync_token: Option<String>,
    /// Metadata about the entity
    #[serde(skip_serializing)]
    pub meta_data: Option<MetaData>,
    /// Name of the class
    pub name: Option<String>,
    /// Reference to the parent class if this is a subclass
    pub parent_ref: Option<NtRef>,
    /// Indicates whether this object is a subclass
    pub sub_class: Option<bool>,
    /// Indicates if the class is active
    pub active: Option<bool>,
    /// Fully qualified name of the class (e.g., Parent:SubClass)
    pub fully_qualified_name: Option<String>,
}

impl QBCreatable for Class {
    fn can_create(&self) -> bool {
        self.id.is_none()
            && self.sync_token.is_none()
            && self.meta_data.is_none()
            && self.name.is_some()
            && if let Some(true) = self.sub_class {
                self.parent_ref.is_some()
            } else {
                true
            }
    }
}

impl QBFullUpdatable for Class {
    fn can_full_update(&self) -> bool {
        self.can_read()
    }
}