1use serde::Deserialize;
2use serde::Serialize;
3use serde_json::value::Value as JsonValue;
4
5use crate::utils::str_or_u32;
6
7#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
8pub struct Phid(pub String);
9
10#[derive(Serialize, Deserialize, Debug)]
11pub struct Cursor {
12 pub before: Option<String>,
13 pub after: Option<String>,
14 #[serde(deserialize_with = "str_or_u32")]
15 pub limit: u32,
16 pub order: Option<String>,
17}
18
19#[derive(Serialize, Debug, Default)]
20pub struct Search<A, C> {
21 #[serde(rename = "queryKey")]
22 pub query_key: Option<String>,
23 pub constraints: C,
24 pub attachments: A,
25}
26
27#[derive(Serialize, Debug)]
28pub struct SearchCursor<'a, A, C> {
29 #[serde(flatten)]
30 pub cursor: &'a Cursor,
31 #[serde(flatten)]
32 pub search: &'a Search<A, C>,
33}
34
35#[derive(Deserialize, Debug)]
36pub struct SearchData<A, F> {
37 pub id: u32,
38 #[serde(rename = "type")]
39 pub ty: String,
40 pub phid: Phid,
41 pub fields: F,
42 pub attachments: A,
43}
44
45#[derive(Deserialize, Debug)]
46pub struct SearchResult<A, F> {
47 pub cursor: Cursor,
48 pub data: Vec<SearchData<A, F>>,
49 #[serde(flatten)]
50 unparsed: JsonValue,
51}