jacquard-api 0.11.0

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.admin.sendEmail
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::string::Did;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SendEmail<'a> {
    ///Additional comment by the sender that won't be used in the email itself but helpful to provide more context for moderators/reviewers
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub comment: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub content: CowStr<'a>,
    #[serde(borrow)]
    pub recipient_did: Did<'a>,
    #[serde(borrow)]
    pub sender_did: Did<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub subject: Option<CowStr<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SendEmailOutput<'a> {
    pub sent: bool,
}

/// Response type for com.atproto.admin.sendEmail
pub struct SendEmailResponse;
impl jacquard_common::xrpc::XrpcResp for SendEmailResponse {
    const NSID: &'static str = "com.atproto.admin.sendEmail";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = SendEmailOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for SendEmail<'a> {
    const NSID: &'static str = "com.atproto.admin.sendEmail";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = SendEmailResponse;
}

/// Endpoint type for com.atproto.admin.sendEmail
pub struct SendEmailRequest;
impl jacquard_common::xrpc::XrpcEndpoint for SendEmailRequest {
    const PATH: &'static str = "/xrpc/com.atproto.admin.sendEmail";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = SendEmail<'de>;
    type Response = SendEmailResponse;
}

pub mod send_email_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type RecipientDid;
        type Content;
        type SenderDid;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type RecipientDid = Unset;
        type Content = Unset;
        type SenderDid = Unset;
    }
    ///State transition - sets the `recipient_did` field to Set
    pub struct SetRecipientDid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRecipientDid<S> {}
    impl<S: State> State for SetRecipientDid<S> {
        type RecipientDid = Set<members::recipient_did>;
        type Content = S::Content;
        type SenderDid = S::SenderDid;
    }
    ///State transition - sets the `content` field to Set
    pub struct SetContent<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetContent<S> {}
    impl<S: State> State for SetContent<S> {
        type RecipientDid = S::RecipientDid;
        type Content = Set<members::content>;
        type SenderDid = S::SenderDid;
    }
    ///State transition - sets the `sender_did` field to Set
    pub struct SetSenderDid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSenderDid<S> {}
    impl<S: State> State for SetSenderDid<S> {
        type RecipientDid = S::RecipientDid;
        type Content = S::Content;
        type SenderDid = Set<members::sender_did>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `recipient_did` field
        pub struct recipient_did(());
        ///Marker type for the `content` field
        pub struct content(());
        ///Marker type for the `sender_did` field
        pub struct sender_did(());
    }
}

/// Builder for constructing an instance of this type
pub struct SendEmailBuilder<'a, S: send_email_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<Did<'a>>,
        Option<Did<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> SendEmail<'a> {
    /// Create a new builder for this type
    pub fn new() -> SendEmailBuilder<'a, send_email_state::Empty> {
        SendEmailBuilder::new()
    }
}

impl<'a> SendEmailBuilder<'a, send_email_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        SendEmailBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: send_email_state::State> SendEmailBuilder<'a, S> {
    /// Set the `comment` field (optional)
    pub fn comment(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `comment` field to an Option value (optional)
    pub fn maybe_comment(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> SendEmailBuilder<'a, S>
where
    S: send_email_state::State,
    S::Content: send_email_state::IsUnset,
{
    /// Set the `content` field (required)
    pub fn content(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> SendEmailBuilder<'a, send_email_state::SetContent<S>> {
        self._fields.1 = Option::Some(value.into());
        SendEmailBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SendEmailBuilder<'a, S>
where
    S: send_email_state::State,
    S::RecipientDid: send_email_state::IsUnset,
{
    /// Set the `recipientDid` field (required)
    pub fn recipient_did(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> SendEmailBuilder<'a, send_email_state::SetRecipientDid<S>> {
        self._fields.2 = Option::Some(value.into());
        SendEmailBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SendEmailBuilder<'a, S>
where
    S: send_email_state::State,
    S::SenderDid: send_email_state::IsUnset,
{
    /// Set the `senderDid` field (required)
    pub fn sender_did(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> SendEmailBuilder<'a, send_email_state::SetSenderDid<S>> {
        self._fields.3 = Option::Some(value.into());
        SendEmailBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: send_email_state::State> SendEmailBuilder<'a, S> {
    /// Set the `subject` field (optional)
    pub fn subject(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `subject` field to an Option value (optional)
    pub fn maybe_subject(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S> SendEmailBuilder<'a, S>
where
    S: send_email_state::State,
    S::RecipientDid: send_email_state::IsSet,
    S::Content: send_email_state::IsSet,
    S::SenderDid: send_email_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> SendEmail<'a> {
        SendEmail {
            comment: self._fields.0,
            content: self._fields.1.unwrap(),
            recipient_did: self._fields.2.unwrap(),
            sender_did: self._fields.3.unwrap(),
            subject: self._fields.4,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> SendEmail<'a> {
        SendEmail {
            comment: self._fields.0,
            content: self._fields.1.unwrap(),
            recipient_did: self._fields.2.unwrap(),
            sender_did: self._fields.3.unwrap(),
            subject: self._fields.4,
            extra_data: Some(extra_data),
        }
    }
}