Skip to main content

jacquard_api/tools_ozone/safelink/
query_events.rs

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