#[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>,
#[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),
}
}
}
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;
}
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 {}
}
pub trait State: sealed::Sealed {
type Body;
type Target;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Body = Unset;
type Target = Unset;
}
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;
}
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>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct body(());
pub struct target(());
}
}
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> {
pub fn new() -> PushNotifyBuilder<'a, push_notify_state::Empty> {
PushNotifyBuilder::new()
}
}
impl<'a> PushNotifyBuilder<'a, push_notify_state::Empty> {
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,
{
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,
{
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,
{
pub fn build(self) -> PushNotify<'a> {
PushNotify {
body: self._fields.0.unwrap(),
target: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
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),
}
}
}