#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::AtUri;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ToggleListItem<S: BosStr = DefaultStr> {
pub game_uri: AtUri<S>,
pub list_uri: AtUri<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, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ToggleListItemOutput<S: BosStr = DefaultStr> {
pub action: ToggleListItemOutputAction<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub uri: Option<AtUri<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ToggleListItemOutputAction<S: BosStr = DefaultStr> {
Added,
Removed,
Other(S),
}
impl<S: BosStr> ToggleListItemOutputAction<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Added => "added",
Self::Removed => "removed",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"added" => Self::Added,
"removed" => Self::Removed,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for ToggleListItemOutputAction<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for ToggleListItemOutputAction<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for ToggleListItemOutputAction<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de>
for ToggleListItemOutputAction<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for ToggleListItemOutputAction<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for ToggleListItemOutputAction<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = ToggleListItemOutputAction<S::Output>;
fn into_static(self) -> Self::Output {
match self {
ToggleListItemOutputAction::Added => ToggleListItemOutputAction::Added,
ToggleListItemOutputAction::Removed => ToggleListItemOutputAction::Removed,
ToggleListItemOutputAction::Other(v) => {
ToggleListItemOutputAction::Other(v.into_static())
}
}
}
}
pub struct ToggleListItemResponse;
impl jacquard_common::xrpc::XrpcResp for ToggleListItemResponse {
const NSID: &'static str = "games.gamesgamesgamesgames.toggleListItem";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ToggleListItemOutput<S>;
type Err = jacquard_common::xrpc::GenericError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ToggleListItem<S> {
const NSID: &'static str = "games.gamesgamesgamesgames.toggleListItem";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = ToggleListItemResponse;
}
pub struct ToggleListItemRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ToggleListItemRequest {
const PATH: &'static str = "/xrpc/games.gamesgamesgamesgames.toggleListItem";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<S: BosStr> = ToggleListItem<S>;
type Response = ToggleListItemResponse;
}
pub mod toggle_list_item_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 GameUri;
type ListUri;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type GameUri = Unset;
type ListUri = Unset;
}
pub struct SetGameUri<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetGameUri<St> {}
impl<St: State> State for SetGameUri<St> {
type GameUri = Set<members::game_uri>;
type ListUri = St::ListUri;
}
pub struct SetListUri<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetListUri<St> {}
impl<St: State> State for SetListUri<St> {
type GameUri = St::GameUri;
type ListUri = Set<members::list_uri>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct game_uri(());
pub struct list_uri(());
}
}
pub struct ToggleListItemBuilder<
St: toggle_list_item_state::State,
S: BosStr = DefaultStr,
> {
_state: PhantomData<fn() -> St>,
_fields: (Option<AtUri<S>>, Option<AtUri<S>>),
_type: PhantomData<fn() -> S>,
}
impl ToggleListItem<DefaultStr> {
pub fn new() -> ToggleListItemBuilder<toggle_list_item_state::Empty, DefaultStr> {
ToggleListItemBuilder::new()
}
}
impl<S: BosStr> ToggleListItem<S> {
pub fn builder() -> ToggleListItemBuilder<toggle_list_item_state::Empty, S> {
ToggleListItemBuilder::builder()
}
}
impl ToggleListItemBuilder<toggle_list_item_state::Empty, DefaultStr> {
pub fn new() -> Self {
ToggleListItemBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> ToggleListItemBuilder<toggle_list_item_state::Empty, S> {
pub fn builder() -> Self {
ToggleListItemBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ToggleListItemBuilder<St, S>
where
St: toggle_list_item_state::State,
St::GameUri: toggle_list_item_state::IsUnset,
{
pub fn game_uri(
mut self,
value: impl Into<AtUri<S>>,
) -> ToggleListItemBuilder<toggle_list_item_state::SetGameUri<St>, S> {
self._fields.0 = Option::Some(value.into());
ToggleListItemBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ToggleListItemBuilder<St, S>
where
St: toggle_list_item_state::State,
St::ListUri: toggle_list_item_state::IsUnset,
{
pub fn list_uri(
mut self,
value: impl Into<AtUri<S>>,
) -> ToggleListItemBuilder<toggle_list_item_state::SetListUri<St>, S> {
self._fields.1 = Option::Some(value.into());
ToggleListItemBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ToggleListItemBuilder<St, S>
where
St: toggle_list_item_state::State,
St::GameUri: toggle_list_item_state::IsSet,
St::ListUri: toggle_list_item_state::IsSet,
{
pub fn build(self) -> ToggleListItem<S> {
ToggleListItem {
game_uri: self._fields.0.unwrap(),
list_uri: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> ToggleListItem<S> {
ToggleListItem {
game_uri: self._fields.0.unwrap(),
list_uri: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}