wave-api 0.1.0

Typed Rust client for the Wave Accounting GraphQL API
Documentation
use serde::Serialize;

use crate::enums::{AccountSubtypeValue, CurrencyCode};

/// Input for creating an account.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountCreateInput {
    pub business_id: String,
    pub name: String,
    pub subtype: AccountSubtypeValue,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub currency: Option<CurrencyCode>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub display_id: Option<String>,
}

impl AccountCreateInput {
    pub fn new(
        business_id: impl Into<String>,
        name: impl Into<String>,
        subtype: AccountSubtypeValue,
    ) -> Self {
        Self {
            business_id: business_id.into(),
            name: name.into(),
            subtype,
            currency: None,
            description: None,
            display_id: None,
        }
    }

    pub fn currency(mut self, v: CurrencyCode) -> Self {
        self.currency = Some(v);
        self
    }
    pub fn description(mut self, v: impl Into<String>) -> Self {
        self.description = Some(v.into());
        self
    }
    pub fn display_id(mut self, v: impl Into<String>) -> Self {
        self.display_id = Some(v.into());
        self
    }
}

/// Input for patching an account.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountPatchInput {
    pub id: String,
    pub sequence: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub display_id: Option<String>,
}

impl AccountPatchInput {
    pub fn new(id: impl Into<String>, sequence: i64) -> Self {
        Self {
            id: id.into(),
            sequence,
            name: None,
            description: None,
            display_id: None,
        }
    }

    pub fn name(mut self, v: impl Into<String>) -> Self {
        self.name = Some(v.into());
        self
    }
    pub fn description(mut self, v: impl Into<String>) -> Self {
        self.description = Some(v.into());
        self
    }
}

/// Input for archiving an account.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountArchiveInput {
    pub id: String,
}

impl AccountArchiveInput {
    pub fn new(id: impl Into<String>) -> Self {
        Self { id: id.into() }
    }
}