#[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 RegisterPush<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub age_restricted: Option<bool>,
#[serde(borrow)]
pub app_id: CowStr<'a>,
#[serde(borrow)]
pub platform: RegisterPushPlatform<'a>,
#[serde(borrow)]
pub service_did: Did<'a>,
#[serde(borrow)]
pub token: CowStr<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RegisterPushPlatform<'a> {
Ios,
Android,
Web,
Other(CowStr<'a>),
}
impl<'a> RegisterPushPlatform<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Ios => "ios",
Self::Android => "android",
Self::Web => "web",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for RegisterPushPlatform<'a> {
fn from(s: &'a str) -> Self {
match s {
"ios" => Self::Ios,
"android" => Self::Android,
"web" => Self::Web,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for RegisterPushPlatform<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"ios" => Self::Ios,
"android" => Self::Android,
"web" => Self::Web,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for RegisterPushPlatform<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for RegisterPushPlatform<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for RegisterPushPlatform<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for RegisterPushPlatform<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for RegisterPushPlatform<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for RegisterPushPlatform<'_> {
type Output = RegisterPushPlatform<'static>;
fn into_static(self) -> Self::Output {
match self {
RegisterPushPlatform::Ios => RegisterPushPlatform::Ios,
RegisterPushPlatform::Android => RegisterPushPlatform::Android,
RegisterPushPlatform::Web => RegisterPushPlatform::Web,
RegisterPushPlatform::Other(v) => {
RegisterPushPlatform::Other(v.into_static())
}
}
}
}
pub struct RegisterPushResponse;
impl jacquard_common::xrpc::XrpcResp for RegisterPushResponse {
const NSID: &'static str = "app.bsky.notification.registerPush";
const ENCODING: &'static str = "application/json";
type Output<'de> = ();
type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcRequest for RegisterPush<'a> {
const NSID: &'static str = "app.bsky.notification.registerPush";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = RegisterPushResponse;
}
pub struct RegisterPushRequest;
impl jacquard_common::xrpc::XrpcEndpoint for RegisterPushRequest {
const PATH: &'static str = "/xrpc/app.bsky.notification.registerPush";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<'de> = RegisterPush<'de>;
type Response = RegisterPushResponse;
}
pub mod register_push_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 ServiceDid;
type Token;
type Platform;
type AppId;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type ServiceDid = Unset;
type Token = Unset;
type Platform = Unset;
type AppId = Unset;
}
pub struct SetServiceDid<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetServiceDid<S> {}
impl<S: State> State for SetServiceDid<S> {
type ServiceDid = Set<members::service_did>;
type Token = S::Token;
type Platform = S::Platform;
type AppId = S::AppId;
}
pub struct SetToken<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetToken<S> {}
impl<S: State> State for SetToken<S> {
type ServiceDid = S::ServiceDid;
type Token = Set<members::token>;
type Platform = S::Platform;
type AppId = S::AppId;
}
pub struct SetPlatform<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPlatform<S> {}
impl<S: State> State for SetPlatform<S> {
type ServiceDid = S::ServiceDid;
type Token = S::Token;
type Platform = Set<members::platform>;
type AppId = S::AppId;
}
pub struct SetAppId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetAppId<S> {}
impl<S: State> State for SetAppId<S> {
type ServiceDid = S::ServiceDid;
type Token = S::Token;
type Platform = S::Platform;
type AppId = Set<members::app_id>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct service_did(());
pub struct token(());
pub struct platform(());
pub struct app_id(());
}
}
pub struct RegisterPushBuilder<'a, S: register_push_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<bool>,
Option<CowStr<'a>>,
Option<RegisterPushPlatform<'a>>,
Option<Did<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> RegisterPush<'a> {
pub fn new() -> RegisterPushBuilder<'a, register_push_state::Empty> {
RegisterPushBuilder::new()
}
}
impl<'a> RegisterPushBuilder<'a, register_push_state::Empty> {
pub fn new() -> Self {
RegisterPushBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: register_push_state::State> RegisterPushBuilder<'a, S> {
pub fn age_restricted(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_age_restricted(mut self, value: Option<bool>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> RegisterPushBuilder<'a, S>
where
S: register_push_state::State,
S::AppId: register_push_state::IsUnset,
{
pub fn app_id(
mut self,
value: impl Into<CowStr<'a>>,
) -> RegisterPushBuilder<'a, register_push_state::SetAppId<S>> {
self._fields.1 = Option::Some(value.into());
RegisterPushBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> RegisterPushBuilder<'a, S>
where
S: register_push_state::State,
S::Platform: register_push_state::IsUnset,
{
pub fn platform(
mut self,
value: impl Into<RegisterPushPlatform<'a>>,
) -> RegisterPushBuilder<'a, register_push_state::SetPlatform<S>> {
self._fields.2 = Option::Some(value.into());
RegisterPushBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> RegisterPushBuilder<'a, S>
where
S: register_push_state::State,
S::ServiceDid: register_push_state::IsUnset,
{
pub fn service_did(
mut self,
value: impl Into<Did<'a>>,
) -> RegisterPushBuilder<'a, register_push_state::SetServiceDid<S>> {
self._fields.3 = Option::Some(value.into());
RegisterPushBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> RegisterPushBuilder<'a, S>
where
S: register_push_state::State,
S::Token: register_push_state::IsUnset,
{
pub fn token(
mut self,
value: impl Into<CowStr<'a>>,
) -> RegisterPushBuilder<'a, register_push_state::SetToken<S>> {
self._fields.4 = Option::Some(value.into());
RegisterPushBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> RegisterPushBuilder<'a, S>
where
S: register_push_state::State,
S::ServiceDid: register_push_state::IsSet,
S::Token: register_push_state::IsSet,
S::Platform: register_push_state::IsSet,
S::AppId: register_push_state::IsSet,
{
pub fn build(self) -> RegisterPush<'a> {
RegisterPush {
age_restricted: self._fields.0,
app_id: self._fields.1.unwrap(),
platform: self._fields.2.unwrap(),
service_did: self._fields.3.unwrap(),
token: self._fields.4.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>,
>,
) -> RegisterPush<'a> {
RegisterPush {
age_restricted: self._fields.0,
app_id: self._fields.1.unwrap(),
platform: self._fields.2.unwrap(),
service_did: self._fields.3.unwrap(),
token: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}