Skip to main content

jacquard_api/tools_ozone/moderation/
get_record.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: tools.ozone.moderation.getRecord
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use core::marker::PhantomData;
10use jacquard_common::CowStr;
11use jacquard_common::types::string::{AtUri, Cid};
12use jacquard_derive::{IntoStatic, open_union};
13use serde::{Serialize, Deserialize};
14use crate::tools_ozone::moderation::RecordViewDetail;
15
16#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
17#[serde(rename_all = "camelCase")]
18pub struct GetRecord<'a> {
19    #[serde(skip_serializing_if = "Option::is_none")]
20    #[serde(borrow)]
21    pub cid: Option<Cid<'a>>,
22    #[serde(borrow)]
23    pub uri: AtUri<'a>,
24}
25
26
27#[jacquard_derive::lexicon]
28#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
29#[serde(rename_all = "camelCase")]
30pub struct GetRecordOutput<'a> {
31    #[serde(flatten)]
32    #[serde(borrow)]
33    pub value: RecordViewDetail<'a>,
34}
35
36
37#[open_union]
38#[derive(
39    Serialize,
40    Deserialize,
41    Debug,
42    Clone,
43    PartialEq,
44    Eq,
45    thiserror::Error,
46    miette::Diagnostic,
47    IntoStatic
48)]
49
50#[serde(tag = "error", content = "message")]
51#[serde(bound(deserialize = "'de: 'a"))]
52pub enum GetRecordError<'a> {
53    #[serde(rename = "RecordNotFound")]
54    RecordNotFound(Option<CowStr<'a>>),
55}
56
57impl core::fmt::Display for GetRecordError<'_> {
58    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
59        match self {
60            Self::RecordNotFound(msg) => {
61                write!(f, "RecordNotFound")?;
62                if let Some(msg) = msg {
63                    write!(f, ": {}", msg)?;
64                }
65                Ok(())
66            }
67            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
68        }
69    }
70}
71
72/// Response type for tools.ozone.moderation.getRecord
73pub struct GetRecordResponse;
74impl jacquard_common::xrpc::XrpcResp for GetRecordResponse {
75    const NSID: &'static str = "tools.ozone.moderation.getRecord";
76    const ENCODING: &'static str = "application/json";
77    type Output<'de> = GetRecordOutput<'de>;
78    type Err<'de> = GetRecordError<'de>;
79}
80
81impl<'a> jacquard_common::xrpc::XrpcRequest for GetRecord<'a> {
82    const NSID: &'static str = "tools.ozone.moderation.getRecord";
83    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
84    type Response = GetRecordResponse;
85}
86
87/// Endpoint type for tools.ozone.moderation.getRecord
88pub struct GetRecordRequest;
89impl jacquard_common::xrpc::XrpcEndpoint for GetRecordRequest {
90    const PATH: &'static str = "/xrpc/tools.ozone.moderation.getRecord";
91    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
92    type Request<'de> = GetRecord<'de>;
93    type Response = GetRecordResponse;
94}
95
96pub mod get_record_state {
97
98    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
99    #[allow(unused)]
100    use ::core::marker::PhantomData;
101    mod sealed {
102        pub trait Sealed {}
103    }
104    /// State trait tracking which required fields have been set
105    pub trait State: sealed::Sealed {
106        type Uri;
107    }
108    /// Empty state - all required fields are unset
109    pub struct Empty(());
110    impl sealed::Sealed for Empty {}
111    impl State for Empty {
112        type Uri = Unset;
113    }
114    ///State transition - sets the `uri` field to Set
115    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
116    impl<S: State> sealed::Sealed for SetUri<S> {}
117    impl<S: State> State for SetUri<S> {
118        type Uri = Set<members::uri>;
119    }
120    /// Marker types for field names
121    #[allow(non_camel_case_types)]
122    pub mod members {
123        ///Marker type for the `uri` field
124        pub struct uri(());
125    }
126}
127
128/// Builder for constructing an instance of this type
129pub struct GetRecordBuilder<'a, S: get_record_state::State> {
130    _state: PhantomData<fn() -> S>,
131    _fields: (Option<Cid<'a>>, Option<AtUri<'a>>),
132    _lifetime: PhantomData<&'a ()>,
133}
134
135impl<'a> GetRecord<'a> {
136    /// Create a new builder for this type
137    pub fn new() -> GetRecordBuilder<'a, get_record_state::Empty> {
138        GetRecordBuilder::new()
139    }
140}
141
142impl<'a> GetRecordBuilder<'a, get_record_state::Empty> {
143    /// Create a new builder with all fields unset
144    pub fn new() -> Self {
145        GetRecordBuilder {
146            _state: PhantomData,
147            _fields: (None, None),
148            _lifetime: PhantomData,
149        }
150    }
151}
152
153impl<'a, S: get_record_state::State> GetRecordBuilder<'a, S> {
154    /// Set the `cid` field (optional)
155    pub fn cid(mut self, value: impl Into<Option<Cid<'a>>>) -> Self {
156        self._fields.0 = value.into();
157        self
158    }
159    /// Set the `cid` field to an Option value (optional)
160    pub fn maybe_cid(mut self, value: Option<Cid<'a>>) -> Self {
161        self._fields.0 = value;
162        self
163    }
164}
165
166impl<'a, S> GetRecordBuilder<'a, S>
167where
168    S: get_record_state::State,
169    S::Uri: get_record_state::IsUnset,
170{
171    /// Set the `uri` field (required)
172    pub fn uri(
173        mut self,
174        value: impl Into<AtUri<'a>>,
175    ) -> GetRecordBuilder<'a, get_record_state::SetUri<S>> {
176        self._fields.1 = Option::Some(value.into());
177        GetRecordBuilder {
178            _state: PhantomData,
179            _fields: self._fields,
180            _lifetime: PhantomData,
181        }
182    }
183}
184
185impl<'a, S> GetRecordBuilder<'a, S>
186where
187    S: get_record_state::State,
188    S::Uri: get_record_state::IsSet,
189{
190    /// Build the final struct
191    pub fn build(self) -> GetRecord<'a> {
192        GetRecord {
193            cid: self._fields.0,
194            uri: self._fields.1.unwrap(),
195        }
196    }
197}