Skip to main content

auto_api_client/
types.rs

1use serde::Deserialize;
2use serde_json::Value;
3
4/// Parameters for `get_offers()`.
5/// Use `..Default::default()` for optional fields.
6#[derive(Debug, Default, Clone)]
7pub struct OffersParams {
8    pub page: i32,
9    pub brand: Option<String>,
10    pub model: Option<String>,
11    pub configuration: Option<String>,
12    pub complectation: Option<String>,
13    pub transmission: Option<String>,
14    pub color: Option<String>,
15    pub body_type: Option<String>,
16    pub engine_type: Option<String>,
17    pub year_from: Option<i32>,
18    pub year_to: Option<i32>,
19    pub mileage_from: Option<i32>,
20    pub mileage_to: Option<i32>,
21    pub price_from: Option<i32>,
22    pub price_to: Option<i32>,
23}
24
25impl OffersParams {
26    /// Converts parameters to a vector of (key, value) pairs for query string.
27    /// Only non-None values are included.
28    pub(crate) fn to_query_pairs(&self) -> Vec<(String, String)> {
29        let mut pairs = vec![("page".to_string(), self.page.to_string())];
30
31        if let Some(ref v) = self.brand { pairs.push(("brand".into(), v.clone())); }
32        if let Some(ref v) = self.model { pairs.push(("model".into(), v.clone())); }
33        if let Some(ref v) = self.configuration { pairs.push(("configuration".into(), v.clone())); }
34        if let Some(ref v) = self.complectation { pairs.push(("complectation".into(), v.clone())); }
35        if let Some(ref v) = self.transmission { pairs.push(("transmission".into(), v.clone())); }
36        if let Some(ref v) = self.color { pairs.push(("color".into(), v.clone())); }
37        if let Some(ref v) = self.body_type { pairs.push(("body_type".into(), v.clone())); }
38        if let Some(ref v) = self.engine_type { pairs.push(("engine_type".into(), v.clone())); }
39        if let Some(v) = self.year_from { pairs.push(("year_from".into(), v.to_string())); }
40        if let Some(v) = self.year_to { pairs.push(("year_to".into(), v.to_string())); }
41        if let Some(v) = self.mileage_from { pairs.push(("mileage_from".into(), v.to_string())); }
42        if let Some(v) = self.mileage_to { pairs.push(("mileage_to".into(), v.to_string())); }
43        if let Some(v) = self.price_from { pairs.push(("price_from".into(), v.to_string())); }
44        if let Some(v) = self.price_to { pairs.push(("price_to".into(), v.to_string())); }
45
46        pairs
47    }
48}
49
50/// Response from `get_offers()` and `get_offer()`.
51#[derive(Debug, Deserialize)]
52pub struct OffersResponse {
53    pub result: Vec<OfferItem>,
54    pub meta: Meta,
55}
56
57/// Response from `get_changes()`.
58#[derive(Debug, Deserialize)]
59pub struct ChangesResponse {
60    pub result: Vec<ChangeItem>,
61    pub meta: ChangesMeta,
62}
63
64/// Pagination metadata for offers.
65#[derive(Debug, Deserialize)]
66pub struct Meta {
67    pub page: i32,
68    pub next_page: i32,
69    pub limit: i32,
70}
71
72/// Pagination metadata for changes feed.
73#[derive(Debug, Deserialize)]
74pub struct ChangesMeta {
75    pub cur_change_id: i64,
76    pub next_change_id: i64,
77    pub limit: i32,
78}
79
80/// A single item in the offers result array.
81/// `data` is `serde_json::Value` because the structure varies between sources.
82#[derive(Debug, Deserialize)]
83pub struct OfferItem {
84    pub id: i64,
85    pub inner_id: String,
86    pub change_type: String,
87    pub created_at: String,
88    pub data: Value,
89}
90
91/// A single item in the changes result array.
92/// `data` is `serde_json::Value` because the structure varies between sources.
93#[derive(Debug, Deserialize)]
94pub struct ChangeItem {
95    pub id: i64,
96    pub inner_id: String,
97    pub change_type: String,
98    pub created_at: String,
99    pub data: Value,
100}
101
102/// Common offer data fields shared across all sources.
103/// Since each source may have additional fields, deserialize from
104/// `OfferItem.data` into this or into your own struct.
105#[derive(Debug, Deserialize)]
106pub struct OfferData {
107    pub inner_id: String,
108    pub url: String,
109    pub mark: String,
110    pub model: String,
111    pub generation: String,
112    pub configuration: String,
113    pub complectation: String,
114    pub year: String,
115    pub color: String,
116    pub price: String,
117    pub km_age: String,
118    pub engine_type: String,
119    pub transmission_type: String,
120    pub body_type: String,
121    pub address: String,
122    pub seller_type: String,
123    pub is_dealer: bool,
124    pub displacement: String,
125    pub offer_created: String,
126    pub images: Vec<String>,
127}
128
129/// Response from `get_change_id()`.
130#[derive(Debug, Deserialize)]
131pub(crate) struct ChangeIdResponse {
132    pub change_id: i64,
133}