#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
use crate::at_inlay::Element;
use crate::at_inlay::Response;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Maybe<S: BosStr = DefaultStr> {
pub children: Data<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub fallback: Option<Element<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct MaybeOutput<S: BosStr = DefaultStr> {
#[serde(flatten)]
pub value: Response<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
pub struct MaybeResponse;
impl jacquard_common::xrpc::XrpcResp for MaybeResponse {
const NSID: &'static str = "at.inlay.Maybe";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = MaybeOutput<S>;
type Err = jacquard_common::xrpc::GenericError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for Maybe<S> {
const NSID: &'static str = "at.inlay.Maybe";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = MaybeResponse;
}
pub struct MaybeRequest;
impl jacquard_common::xrpc::XrpcEndpoint for MaybeRequest {
const PATH: &'static str = "/xrpc/at.inlay.Maybe";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<S: BosStr> = Maybe<S>;
type Response = MaybeResponse;
}
pub mod maybe_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 Children;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Children = Unset;
}
pub struct SetChildren<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetChildren<St> {}
impl<St: State> State for SetChildren<St> {
type Children = Set<members::children>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct children(());
}
}
pub struct MaybeBuilder<S: BosStr, St: maybe_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Data<S>>, Option<Element<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Maybe<S> {
pub fn new() -> MaybeBuilder<S, maybe_state::Empty> {
MaybeBuilder::new()
}
}
impl<S: BosStr> MaybeBuilder<S, maybe_state::Empty> {
pub fn new() -> Self {
MaybeBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> MaybeBuilder<S, St>
where
St: maybe_state::State,
St::Children: maybe_state::IsUnset,
{
pub fn children(
mut self,
value: impl Into<Data<S>>,
) -> MaybeBuilder<S, maybe_state::SetChildren<St>> {
self._fields.0 = Option::Some(value.into());
MaybeBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: maybe_state::State> MaybeBuilder<S, St> {
pub fn fallback(mut self, value: impl Into<Option<Element<S>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_fallback(mut self, value: Option<Element<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> MaybeBuilder<S, St>
where
St: maybe_state::State,
St::Children: maybe_state::IsSet,
{
pub fn build(self) -> Maybe<S> {
Maybe {
children: self._fields.0.unwrap(),
fallback: self._fields.1,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Maybe<S> {
Maybe {
children: self._fields.0.unwrap(),
fallback: self._fields.1,
extra_data: Some(extra_data),
}
}
}