funpay_client/models/
mod.rs

1pub mod enums;
2pub mod ids;
3
4use crate::models::enums::OrderStatus;
5use crate::models::ids::{ChatId, OrderId};
6use std::collections::HashMap;
7
8#[derive(Debug, Clone, Default)]
9pub struct OfferEditParams {
10    pub quantity: Option<String>,
11    pub quantity2: Option<String>,
12    pub method: Option<String>,
13    pub offer_type: Option<String>,
14    pub server_id: Option<String>,
15    pub desc_ru: Option<String>,
16    pub desc_en: Option<String>,
17    pub payment_msg_ru: Option<String>,
18    pub payment_msg_en: Option<String>,
19    pub summary_ru: Option<String>,
20    pub summary_en: Option<String>,
21    pub game: Option<String>,
22    pub images: Option<String>,
23    pub price: Option<String>,
24    pub deactivate_after_sale: Option<bool>,
25    pub active: Option<bool>,
26    pub location: Option<String>,
27    pub deleted: Option<bool>,
28}
29
30#[derive(Debug, Clone, Default)]
31pub struct OfferFullParams {
32    pub offer_id: i64,
33    pub node_id: i64,
34    pub quantity: Option<String>,
35    pub quantity2: Option<String>,
36    pub method: Option<String>,
37    pub offer_type: Option<String>,
38    pub server_id: Option<String>,
39    pub desc_ru: Option<String>,
40    pub desc_en: Option<String>,
41    pub payment_msg_ru: Option<String>,
42    pub payment_msg_en: Option<String>,
43    pub images: Option<String>,
44    pub price: Option<String>,
45    pub deactivate_after_sale: bool,
46    pub active: bool,
47    pub location: Option<String>,
48    pub custom_fields: Vec<OfferCustomField>,
49}
50
51#[derive(Debug, Clone)]
52pub struct OfferCustomField {
53    pub name: String,
54    pub label: String,
55    pub field_type: OfferFieldType,
56    pub value: String,
57    pub options: Vec<OfferFieldOption>,
58}
59
60#[derive(Debug, Clone)]
61pub struct OfferFieldOption {
62    pub value: String,
63    pub label: String,
64    pub selected: bool,
65}
66
67#[derive(Debug, Clone, PartialEq)]
68pub enum OfferFieldType {
69    Text,
70    Textarea,
71    Select,
72    Checkbox,
73    Hidden,
74    Unknown(String),
75}
76
77impl OfferEditParams {
78    pub fn new() -> Self {
79        Self::default()
80    }
81
82    pub fn with_price(mut self, price: impl Into<String>) -> Self {
83        self.price = Some(price.into());
84        self
85    }
86
87    pub fn with_quantity(mut self, quantity: impl Into<String>) -> Self {
88        self.quantity = Some(quantity.into());
89        self
90    }
91
92    pub fn with_desc_ru(mut self, desc: impl Into<String>) -> Self {
93        self.desc_ru = Some(desc.into());
94        self
95    }
96
97    pub fn with_desc_en(mut self, desc: impl Into<String>) -> Self {
98        self.desc_en = Some(desc.into());
99        self
100    }
101
102    pub fn with_method(mut self, method: impl Into<String>) -> Self {
103        self.method = Some(method.into());
104        self
105    }
106
107    pub fn with_server_id(mut self, server_id: impl Into<String>) -> Self {
108        self.server_id = Some(server_id.into());
109        self
110    }
111
112    pub fn with_deactivate_after_sale(mut self, deactivate: bool) -> Self {
113        self.deactivate_after_sale = Some(deactivate);
114        self
115    }
116
117    pub fn with_active(mut self, active: bool) -> Self {
118        self.active = Some(active);
119        self
120    }
121
122    pub fn with_images(mut self, images: impl Into<String>) -> Self {
123        self.images = Some(images.into());
124        self
125    }
126
127    pub fn with_payment_msg_ru(mut self, msg: impl Into<String>) -> Self {
128        self.payment_msg_ru = Some(msg.into());
129        self
130    }
131
132    pub fn with_payment_msg_en(mut self, msg: impl Into<String>) -> Self {
133        self.payment_msg_en = Some(msg.into());
134        self
135    }
136
137    pub fn with_deleted(mut self, deleted: bool) -> Self {
138        self.deleted = Some(deleted);
139        self
140    }
141
142    pub fn merge(self, other: OfferEditParams) -> Self {
143        Self {
144            quantity: other.quantity.filter(|s| !s.is_empty()).or(self.quantity),
145            quantity2: other.quantity2.filter(|s| !s.is_empty()).or(self.quantity2),
146            method: other.method.filter(|s| !s.is_empty()).or(self.method),
147            offer_type: other
148                .offer_type
149                .filter(|s| !s.is_empty())
150                .or(self.offer_type),
151            server_id: other.server_id.filter(|s| !s.is_empty()).or(self.server_id),
152            desc_ru: other.desc_ru.filter(|s| !s.is_empty()).or(self.desc_ru),
153            desc_en: other.desc_en.filter(|s| !s.is_empty()).or(self.desc_en),
154            payment_msg_ru: other
155                .payment_msg_ru
156                .filter(|s| !s.is_empty())
157                .or(self.payment_msg_ru),
158            payment_msg_en: other
159                .payment_msg_en
160                .filter(|s| !s.is_empty())
161                .or(self.payment_msg_en),
162            summary_ru: other
163                .summary_ru
164                .filter(|s| !s.is_empty())
165                .or(self.summary_ru),
166            summary_en: other
167                .summary_en
168                .filter(|s| !s.is_empty())
169                .or(self.summary_en),
170            game: other.game.filter(|s| !s.is_empty()).or(self.game),
171            images: other.images.filter(|s| !s.is_empty()).or(self.images),
172            price: other.price.filter(|s| !s.is_empty()).or(self.price),
173            deactivate_after_sale: other.deactivate_after_sale.or(self.deactivate_after_sale),
174            active: other.active.or(self.active),
175            location: other.location.filter(|s| !s.is_empty()).or(self.location),
176            deleted: other.deleted.or(self.deleted),
177        }
178    }
179}
180
181#[derive(Debug, Clone)]
182pub struct Offer {
183    pub id: i64,
184    pub node_id: i64,
185    pub description: String,
186    pub price: f64,
187    pub currency: String,
188    pub active: bool,
189}
190
191#[derive(Debug, Clone)]
192pub struct MarketOffer {
193    pub id: i64,
194    pub node_id: i64,
195    pub description: String,
196    pub price: f64,
197    pub currency: String,
198    pub seller_id: i64,
199    pub seller_name: String,
200    pub seller_online: bool,
201    pub seller_rating: Option<f64>,
202    pub seller_reviews: u32,
203    pub is_promo: bool,
204}
205
206#[derive(Debug, Clone)]
207pub struct ChatShortcut {
208    pub id: i64,
209    pub name: String,
210    pub last_message_text: Option<String>,
211    pub node_msg_id: i64,
212    pub user_msg_id: i64,
213    pub unread: bool,
214}
215
216#[derive(Debug, Clone)]
217pub struct Message {
218    pub id: i64,
219    pub chat_id: ChatId,
220    pub chat_name: Option<String>,
221    pub text: Option<String>,
222    pub interlocutor_id: Option<i64>,
223    pub author_id: i64,
224}
225
226#[derive(Debug, Clone)]
227pub struct OrderShortcut {
228    pub id: OrderId,
229    pub description: String,
230    pub price: f64,
231    pub currency: String,
232    pub buyer_username: String,
233    pub buyer_id: i64,
234    pub chat_id: ChatId,
235    pub status: OrderStatus,
236    pub date_text: String,
237    pub subcategory: Subcategory,
238    pub amount: i32,
239}
240
241#[derive(Debug, Clone)]
242pub struct Review {
243    pub stars: Option<i32>,
244    pub text: Option<String>,
245    pub reply: Option<String>,
246    pub anonymous: bool,
247    pub html: String,
248    pub hidden: bool,
249    pub order_id: Option<OrderId>,
250    pub author: Option<String>,
251    pub author_id: Option<i64>,
252    pub by_bot: bool,
253    pub reply_by_bot: bool,
254}
255
256#[derive(Debug, Clone)]
257pub struct Subcategory {
258    pub id: Option<i64>,
259    pub name: String,
260}
261
262#[derive(Debug, Clone)]
263pub struct CategorySubcategory {
264    pub id: i64,
265    pub name: String,
266    pub offer_count: u32,
267    pub subcategory_type: CategorySubcategoryType,
268    pub is_active: bool,
269}
270
271#[derive(Debug, Clone, Copy, PartialEq, Eq)]
272pub enum CategorySubcategoryType {
273    Lots,
274    Chips,
275}
276
277#[derive(Debug, Clone)]
278pub struct CategoryFilter {
279    pub id: String,
280    pub name: String,
281    pub filter_type: CategoryFilterType,
282    pub options: Vec<CategoryFilterOption>,
283}
284
285#[derive(Debug, Clone)]
286pub struct CategoryFilterOption {
287    pub value: String,
288    pub label: String,
289}
290
291#[derive(Debug, Clone, Copy, PartialEq, Eq)]
292pub enum CategoryFilterType {
293    Select,
294    RadioBox,
295    Range,
296    Checkbox,
297}
298
299#[derive(Debug, Clone)]
300pub struct Order {
301    pub id: OrderId,
302    pub status: OrderStatus,
303    pub lot_params: Vec<(String, String)>,
304    pub buyer_params: HashMap<String, String>,
305    pub short_description: Option<String>,
306    pub full_description: Option<String>,
307    pub subcategory: Option<Subcategory>,
308    pub amount: i32,
309    pub sum: f64,
310    pub currency: String,
311    pub buyer_id: i64,
312    pub buyer_username: String,
313    pub seller_id: i64,
314    pub seller_username: String,
315    pub chat_id: ChatId,
316    pub html: String,
317    pub review: Option<Review>,
318    pub order_secrets: Vec<String>,
319}