zulip-api 0.0.8

Client library for interacting with the Zulip API
Documentation
use serde::{Deserialize, Serialize};

use crate::{field_access, impl_default, impl_display};

/// OnboardingStep : Dictionary containing details of a single onboarding step.
///
/// Modified from `openapi-generator-cli` output:
///
/// ```shell,no_build,no_run
/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
/// ```
///
/// ```text
/// /*
/// * Zulip REST API
/// *
/// * Powerful open source group chat
/// *
/// * The version of the OpenAPI document: 1.0.0
/// *
/// * Generated by: https://openapi-generator.tech
/// */
/// ```
///
/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
///
/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct OnboardingStep {
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    onboarding_type: Option<OnboardingType>,
    #[serde(skip_serializing_if = "Option::is_none")]
    name: Option<String>,
}

impl OnboardingStep {
    /// Creates a new [OnboardingStep].
    pub const fn new() -> Self {
        OnboardingStep {
            onboarding_type: None,
            name: None,
        }
    }
}

field_access! {
    OnboardingStep {
        /// The type of the onboarding step.
        onboarding_type: option { OnboardingType },
    }
}

field_access! {
    OnboardingStep {
        /// The name of the onboarding step.
        name: option_cow_deref { str, String },
    }
}

impl_default!(OnboardingStep);
impl_display!(OnboardingStep);

/// Represents the [OnboardingStep] type.
///
/// Valid value is `\"one_time_notice\"`.
///
/// **Changes**: Removed type `\"hotspot\"` in Zulip 9.0 (feature level 259).  New in Zulip 8.0 (feature level 233).
#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum OnboardingType {
    OneTimeNotice,
}

impl OnboardingType {
    /// Creates a new [OnboardingType].
    pub const fn new() -> Self {
        Self::OneTimeNotice
    }
}

impl_default!(OnboardingType);
impl_display!(OnboardingType);

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_onboarding_step() {
        let onboarding_type = OnboardingType::new();
        let name = "test name";

        let step = OnboardingStep::new()
            .with_onboarding_type(onboarding_type)
            .with_name(name);
        let step_json = step.to_string();

        assert_eq!(serde_json::to_string(&step).unwrap(), step_json);
        assert_eq!(
            serde_json::from_str::<OnboardingStep>(&step_json).unwrap(),
            step
        );

        assert_eq!(step.onboarding_type(), Some(onboarding_type));
        assert_eq!(step.name(), Some(name));
    }
}