jacquard-api 0.11.1

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: win.tomo-x.pushat.pushNotify
//
// 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, open_union};
use serde::{Serialize, Deserialize};
use crate::win_tomo_x::pushat::NotifyBody;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PushNotify<'a> {
    #[serde(borrow)]
    pub body: NotifyBody<'a>,
    ///The DID of the target user to whom the notification will be sent.
    #[serde(borrow)]
    pub target: Did<'a>,
}


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

#[open_union]
#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic,
    IntoStatic
)]

#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum PushNotifyError<'a> {
    #[serde(rename = "ServiceNotAllowedError")]
    ServiceNotAllowedError(Option<CowStr<'a>>),
    #[serde(rename = "DeviceNotFoundError")]
    DeviceNotFoundError(Option<CowStr<'a>>),
}

impl core::fmt::Display for PushNotifyError<'_> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::ServiceNotAllowedError(msg) => {
                write!(f, "ServiceNotAllowedError")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::DeviceNotFoundError(msg) => {
                write!(f, "DeviceNotFoundError")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
        }
    }
}

/// Response type for win.tomo-x.pushat.pushNotify
pub struct PushNotifyResponse;
impl jacquard_common::xrpc::XrpcResp for PushNotifyResponse {
    const NSID: &'static str = "win.tomo-x.pushat.pushNotify";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = PushNotifyOutput<'de>;
    type Err<'de> = PushNotifyError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for PushNotify<'a> {
    const NSID: &'static str = "win.tomo-x.pushat.pushNotify";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = PushNotifyResponse;
}

/// Endpoint type for win.tomo-x.pushat.pushNotify
pub struct PushNotifyRequest;
impl jacquard_common::xrpc::XrpcEndpoint for PushNotifyRequest {
    const PATH: &'static str = "/xrpc/win.tomo-x.pushat.pushNotify";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = PushNotify<'de>;
    type Response = PushNotifyResponse;
}

pub mod push_notify_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 Body;
        type Target;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Body = Unset;
        type Target = Unset;
    }
    ///State transition - sets the `body` field to Set
    pub struct SetBody<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetBody<S> {}
    impl<S: State> State for SetBody<S> {
        type Body = Set<members::body>;
        type Target = S::Target;
    }
    ///State transition - sets the `target` field to Set
    pub struct SetTarget<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTarget<S> {}
    impl<S: State> State for SetTarget<S> {
        type Body = S::Body;
        type Target = Set<members::target>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `body` field
        pub struct body(());
        ///Marker type for the `target` field
        pub struct target(());
    }
}

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

impl<'a> PushNotify<'a> {
    /// Create a new builder for this type
    pub fn new() -> PushNotifyBuilder<'a, push_notify_state::Empty> {
        PushNotifyBuilder::new()
    }
}

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

impl<'a, S> PushNotifyBuilder<'a, S>
where
    S: push_notify_state::State,
    S::Body: push_notify_state::IsUnset,
{
    /// Set the `body` field (required)
    pub fn body(
        mut self,
        value: impl Into<NotifyBody<'a>>,
    ) -> PushNotifyBuilder<'a, push_notify_state::SetBody<S>> {
        self._fields.0 = Option::Some(value.into());
        PushNotifyBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PushNotifyBuilder<'a, S>
where
    S: push_notify_state::State,
    S::Target: push_notify_state::IsUnset,
{
    /// Set the `target` field (required)
    pub fn target(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> PushNotifyBuilder<'a, push_notify_state::SetTarget<S>> {
        self._fields.1 = Option::Some(value.into());
        PushNotifyBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PushNotifyBuilder<'a, S>
where
    S: push_notify_state::State,
    S::Body: push_notify_state::IsSet,
    S::Target: push_notify_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> PushNotify<'a> {
        PushNotify {
            body: self._fields.0.unwrap(),
            target: self._fields.1.unwrap(),
            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>,
        >,
    ) -> PushNotify<'a> {
        PushNotify {
            body: self._fields.0.unwrap(),
            target: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}