Skip to main content

jacquard_api/tools_ozone/safelink/
query_rules.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: tools.ozone.safelink.queryRules
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 alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::string::Did;
15use jacquard_derive::{IntoStatic, lexicon};
16use serde::{Serialize, Deserialize};
17use crate::tools_ozone::safelink::UrlRule;
18
19#[lexicon]
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
21#[serde(rename_all = "camelCase")]
22pub struct QueryRules<'a> {
23    ///Filter by action types
24    #[serde(skip_serializing_if = "Option::is_none")]
25    #[serde(borrow)]
26    pub actions: Option<Vec<CowStr<'a>>>,
27    ///Filter by rule creator
28    #[serde(skip_serializing_if = "Option::is_none")]
29    #[serde(borrow)]
30    pub created_by: Option<Did<'a>>,
31    ///Cursor for pagination
32    #[serde(skip_serializing_if = "Option::is_none")]
33    #[serde(borrow)]
34    pub cursor: Option<CowStr<'a>>,
35    ///Maximum number of results to return  Defaults to `50`.
36    #[serde(skip_serializing_if = "Option::is_none")]
37    #[serde(default = "_default_query_rules_limit")]
38    pub limit: Option<i64>,
39    ///Filter by pattern type
40    #[serde(skip_serializing_if = "Option::is_none")]
41    #[serde(borrow)]
42    pub pattern_type: Option<CowStr<'a>>,
43    ///Filter by reason type
44    #[serde(skip_serializing_if = "Option::is_none")]
45    #[serde(borrow)]
46    pub reason: Option<CowStr<'a>>,
47    ///Sort direction
48    #[serde(skip_serializing_if = "Option::is_none")]
49    #[serde(borrow)]
50    pub sort_direction: Option<QueryRulesSortDirection<'a>>,
51    ///Filter by specific URLs or domains
52    #[serde(skip_serializing_if = "Option::is_none")]
53    #[serde(borrow)]
54    pub urls: Option<Vec<CowStr<'a>>>,
55}
56
57/// Sort direction
58
59#[derive(Debug, Clone, PartialEq, Eq, Hash)]
60pub enum QueryRulesSortDirection<'a> {
61    Asc,
62    Desc,
63    Other(CowStr<'a>),
64}
65
66impl<'a> QueryRulesSortDirection<'a> {
67    pub fn as_str(&self) -> &str {
68        match self {
69            Self::Asc => "asc",
70            Self::Desc => "desc",
71            Self::Other(s) => s.as_ref(),
72        }
73    }
74}
75
76impl<'a> From<&'a str> for QueryRulesSortDirection<'a> {
77    fn from(s: &'a str) -> Self {
78        match s {
79            "asc" => Self::Asc,
80            "desc" => Self::Desc,
81            _ => Self::Other(CowStr::from(s)),
82        }
83    }
84}
85
86impl<'a> From<String> for QueryRulesSortDirection<'a> {
87    fn from(s: String) -> Self {
88        match s.as_str() {
89            "asc" => Self::Asc,
90            "desc" => Self::Desc,
91            _ => Self::Other(CowStr::from(s)),
92        }
93    }
94}
95
96impl<'a> core::fmt::Display for QueryRulesSortDirection<'a> {
97    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
98        write!(f, "{}", self.as_str())
99    }
100}
101
102impl<'a> AsRef<str> for QueryRulesSortDirection<'a> {
103    fn as_ref(&self) -> &str {
104        self.as_str()
105    }
106}
107
108impl<'a> serde::Serialize for QueryRulesSortDirection<'a> {
109    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
110    where
111        S: serde::Serializer,
112    {
113        serializer.serialize_str(self.as_str())
114    }
115}
116
117impl<'de, 'a> serde::Deserialize<'de> for QueryRulesSortDirection<'a>
118where
119    'de: 'a,
120{
121    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
122    where
123        D: serde::Deserializer<'de>,
124    {
125        let s = <&'de str>::deserialize(deserializer)?;
126        Ok(Self::from(s))
127    }
128}
129
130impl<'a> Default for QueryRulesSortDirection<'a> {
131    fn default() -> Self {
132        Self::Other(Default::default())
133    }
134}
135
136impl jacquard_common::IntoStatic for QueryRulesSortDirection<'_> {
137    type Output = QueryRulesSortDirection<'static>;
138    fn into_static(self) -> Self::Output {
139        match self {
140            QueryRulesSortDirection::Asc => QueryRulesSortDirection::Asc,
141            QueryRulesSortDirection::Desc => QueryRulesSortDirection::Desc,
142            QueryRulesSortDirection::Other(v) => {
143                QueryRulesSortDirection::Other(v.into_static())
144            }
145        }
146    }
147}
148
149
150#[lexicon]
151#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
152#[serde(rename_all = "camelCase")]
153pub struct QueryRulesOutput<'a> {
154    ///Next cursor for pagination. Only present if there are more results.
155    #[serde(skip_serializing_if = "Option::is_none")]
156    #[serde(borrow)]
157    pub cursor: Option<CowStr<'a>>,
158    #[serde(borrow)]
159    pub rules: Vec<UrlRule<'a>>,
160}
161
162/// Response type for tools.ozone.safelink.queryRules
163pub struct QueryRulesResponse;
164impl jacquard_common::xrpc::XrpcResp for QueryRulesResponse {
165    const NSID: &'static str = "tools.ozone.safelink.queryRules";
166    const ENCODING: &'static str = "application/json";
167    type Output<'de> = QueryRulesOutput<'de>;
168    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
169}
170
171impl<'a> jacquard_common::xrpc::XrpcRequest for QueryRules<'a> {
172    const NSID: &'static str = "tools.ozone.safelink.queryRules";
173    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
174        "application/json",
175    );
176    type Response = QueryRulesResponse;
177}
178
179/// Endpoint type for tools.ozone.safelink.queryRules
180pub struct QueryRulesRequest;
181impl jacquard_common::xrpc::XrpcEndpoint for QueryRulesRequest {
182    const PATH: &'static str = "/xrpc/tools.ozone.safelink.queryRules";
183    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
184        "application/json",
185    );
186    type Request<'de> = QueryRules<'de>;
187    type Response = QueryRulesResponse;
188}
189
190fn _default_query_rules_limit() -> Option<i64> {
191    Some(50i64)
192}