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};

/// Represents a scheduled message.
///
/// 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 ScheduledMessage {
    #[serde(skip_serializing_if = "Option::is_none")]
    scheduled_message_id: Option<u64>,
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    scheduled_message_type: Option<ScheduledMessageType>,
    #[serde(skip_serializing_if = "Option::is_none")]
    to: Option<ScheduledMessageTo>,
    #[serde(skip_serializing_if = "Option::is_none")]
    topic: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    content: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    rendered_content: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    scheduled_delivery_timestamp: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    failed: Option<bool>,
}

impl ScheduledMessage {
    /// Creates a new [ScheduledMessage].
    pub const fn new() -> Self {
        ScheduledMessage {
            scheduled_message_id: None,
            scheduled_message_type: None,
            to: None,
            topic: None,
            content: None,
            rendered_content: None,
            scheduled_delivery_timestamp: None,
            failed: None,
        }
    }
}

field_access! {
    ScheduledMessage {
        scheduled_message_id: option { u64 },
        scheduled_message_type: option { ScheduledMessageType },
        scheduled_delivery_timestamp: option { u64 },
        failed: option { bool },
    }
}

field_access! {
    ScheduledMessage {
        to: option_ref { ScheduledMessageTo },
    }
}

field_access! {
    ScheduledMessage {
        topic: option_cow_deref { str, String },
        content: option_cow_deref { str, String },
        rendered_content: option_cow_deref { str, String },
    }
}

impl_default!(ScheduledMessage);
impl_display!(ScheduledMessage);

/// Represents the [ScheduledMessage] type.
///
/// 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, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ScheduledMessageType {
    Stream,
    Private,
}

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

impl_default!(ScheduledMessageType);
impl_display!(ScheduledMessageType);

/// Represents the scheduled message's tentative target audience.
///
/// - For channel messages, it will be the unique ID of the target channel.
/// - For direct messages, it will be an array with the target users' IDs.
///
/// 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)]
#[serde(untagged)]
pub enum ScheduledMessageTo {
    ChannelId(u64),
    UserIds(Vec<u64>),
}

impl ScheduledMessageTo {
    /// Creates a new [ScheduledMessageTo].
    pub const fn new() -> Self {
        Self::ChannelId(0)
    }
}

impl_default!(ScheduledMessageTo);
impl_display!(ScheduledMessageTo);