jacquard_api/games_gamesgamesgamesgames/graph/
toggle_like.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::deps::smol_str::SmolStr;
14use jacquard_common::types::string::AtUri;
15use jacquard_common::types::value::Data;
16use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
17use jacquard_derive::IntoStatic;
18use serde::{Deserialize, Serialize};
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(
22 rename_all = "camelCase",
23 bound(deserialize = "S: Deserialize<'de> + BosStr")
24)]
25pub struct ToggleLike<S: BosStr = DefaultStr> {
26 pub subject: AtUri<S>,
28 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
29 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
30}
31
32#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
33#[serde(
34 rename_all = "camelCase",
35 bound(deserialize = "S: Deserialize<'de> + BosStr")
36)]
37pub struct ToggleLikeOutput<S: BosStr = DefaultStr> {
38 pub action: ToggleLikeOutputAction<S>,
40 #[serde(skip_serializing_if = "Option::is_none")]
42 pub cid: Option<S>,
43 #[serde(skip_serializing_if = "Option::is_none")]
45 pub uri: Option<AtUri<S>>,
46 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
47 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
48}
49
50#[derive(Debug, Clone, PartialEq, Eq, Hash)]
53pub enum ToggleLikeOutputAction<S: BosStr = DefaultStr> {
54 Liked,
55 Unliked,
56 Other(S),
57}
58
59impl<S: BosStr> ToggleLikeOutputAction<S> {
60 pub fn as_str(&self) -> &str {
61 match self {
62 Self::Liked => "liked",
63 Self::Unliked => "unliked",
64 Self::Other(s) => s.as_ref(),
65 }
66 }
67 pub fn from_value(s: S) -> Self {
69 match s.as_ref() {
70 "liked" => Self::Liked,
71 "unliked" => Self::Unliked,
72 _ => Self::Other(s),
73 }
74 }
75}
76
77impl<S: BosStr> core::fmt::Display for ToggleLikeOutputAction<S> {
78 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
79 write!(f, "{}", self.as_str())
80 }
81}
82
83impl<S: BosStr> AsRef<str> for ToggleLikeOutputAction<S> {
84 fn as_ref(&self) -> &str {
85 self.as_str()
86 }
87}
88
89impl<S: BosStr> Serialize for ToggleLikeOutputAction<S> {
90 fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
91 where
92 Ser: serde::Serializer,
93 {
94 serializer.serialize_str(self.as_str())
95 }
96}
97
98impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ToggleLikeOutputAction<S> {
99 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
100 where
101 D: serde::Deserializer<'de>,
102 {
103 let s = S::deserialize(deserializer)?;
104 Ok(Self::from_value(s))
105 }
106}
107
108impl<S: BosStr + Default> Default for ToggleLikeOutputAction<S> {
109 fn default() -> Self {
110 Self::Other(Default::default())
111 }
112}
113
114impl<S: BosStr> jacquard_common::IntoStatic for ToggleLikeOutputAction<S>
115where
116 S: BosStr + jacquard_common::IntoStatic,
117 S::Output: BosStr,
118{
119 type Output = ToggleLikeOutputAction<S::Output>;
120 fn into_static(self) -> Self::Output {
121 match self {
122 ToggleLikeOutputAction::Liked => ToggleLikeOutputAction::Liked,
123 ToggleLikeOutputAction::Unliked => ToggleLikeOutputAction::Unliked,
124 ToggleLikeOutputAction::Other(v) => ToggleLikeOutputAction::Other(v.into_static()),
125 }
126 }
127}
128
129pub struct ToggleLikeResponse;
133impl jacquard_common::xrpc::XrpcResp for ToggleLikeResponse {
134 const NSID: &'static str = "games.gamesgamesgamesgames.graph.toggleLike";
135 const ENCODING: &'static str = "application/json";
136 type Output<S: BosStr> = ToggleLikeOutput<S>;
137 type Err = jacquard_common::xrpc::GenericError;
138}
139
140impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ToggleLike<S> {
141 const NSID: &'static str = "games.gamesgamesgamesgames.graph.toggleLike";
142 const METHOD: jacquard_common::xrpc::XrpcMethod =
143 jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
144 type Response = ToggleLikeResponse;
145}
146
147pub struct ToggleLikeRequest;
151impl jacquard_common::xrpc::XrpcEndpoint for ToggleLikeRequest {
152 const PATH: &'static str = "/xrpc/games.gamesgamesgamesgames.graph.toggleLike";
153 const METHOD: jacquard_common::xrpc::XrpcMethod =
154 jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
155 type Request<S: BosStr> = ToggleLike<S>;
156 type Response = ToggleLikeResponse;
157}
158
159pub mod toggle_like_state {
160
161 pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
162 #[allow(unused)]
163 use ::core::marker::PhantomData;
164 mod sealed {
165 pub trait Sealed {}
166 }
167 pub trait State: sealed::Sealed {
169 type Subject;
170 }
171 pub struct Empty(());
173 impl sealed::Sealed for Empty {}
174 impl State for Empty {
175 type Subject = Unset;
176 }
177 pub struct SetSubject<St: State = Empty>(PhantomData<fn() -> St>);
179 impl<St: State> sealed::Sealed for SetSubject<St> {}
180 impl<St: State> State for SetSubject<St> {
181 type Subject = Set<members::subject>;
182 }
183 #[allow(non_camel_case_types)]
185 pub mod members {
186 pub struct subject(());
188 }
189}
190
191pub struct ToggleLikeBuilder<St: toggle_like_state::State, S: BosStr = DefaultStr> {
193 _state: PhantomData<fn() -> St>,
194 _fields: (Option<AtUri<S>>,),
195 _type: PhantomData<fn() -> S>,
196}
197
198impl ToggleLike<DefaultStr> {
199 pub fn new() -> ToggleLikeBuilder<toggle_like_state::Empty, DefaultStr> {
201 ToggleLikeBuilder::new()
202 }
203}
204
205impl<S: BosStr> ToggleLike<S> {
206 pub fn builder() -> ToggleLikeBuilder<toggle_like_state::Empty, S> {
208 ToggleLikeBuilder::builder()
209 }
210}
211
212impl ToggleLikeBuilder<toggle_like_state::Empty, DefaultStr> {
213 pub fn new() -> Self {
215 ToggleLikeBuilder {
216 _state: PhantomData,
217 _fields: (None,),
218 _type: PhantomData,
219 }
220 }
221}
222
223impl<S: BosStr> ToggleLikeBuilder<toggle_like_state::Empty, S> {
224 pub fn builder() -> Self {
226 ToggleLikeBuilder {
227 _state: PhantomData,
228 _fields: (None,),
229 _type: PhantomData,
230 }
231 }
232}
233
234impl<St, S: BosStr> ToggleLikeBuilder<St, S>
235where
236 St: toggle_like_state::State,
237 St::Subject: toggle_like_state::IsUnset,
238{
239 pub fn subject(
241 mut self,
242 value: impl Into<AtUri<S>>,
243 ) -> ToggleLikeBuilder<toggle_like_state::SetSubject<St>, S> {
244 self._fields.0 = Option::Some(value.into());
245 ToggleLikeBuilder {
246 _state: PhantomData,
247 _fields: self._fields,
248 _type: PhantomData,
249 }
250 }
251}
252
253impl<St, S: BosStr> ToggleLikeBuilder<St, S>
254where
255 St: toggle_like_state::State,
256 St::Subject: toggle_like_state::IsSet,
257{
258 pub fn build(self) -> ToggleLike<S> {
260 ToggleLike {
261 subject: self._fields.0.unwrap(),
262 extra_data: Default::default(),
263 }
264 }
265 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> ToggleLike<S> {
267 ToggleLike {
268 subject: self._fields.0.unwrap(),
269 extra_data: Some(extra_data),
270 }
271 }
272}