1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
//! Conversations between a buyer and a shop's team.
//!
//! There is one conversation per buyer, shop and mode. The buyer side (the
//! shop's customer portal and the buyer account) and the team side (the
//! dashboard inbox) see the same conversation through different shapes.
//!
//! `Debug` on the team-side summary prints no buyer name or email address.
use std::fmt;
use serde::Deserialize;
use serde_json::Value;
use crate::core::models::buyer_case::BuyerCaseEvent;
/// A file a message carries, or one uploaded for the next message.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationAttachment {
/// File id, named in a message's `attachments`.
pub id: String,
/// The name it was uploaded under.
pub file_name: String,
/// `pdf`, `png`, `jpeg`, `webp` or `text`.
pub file_type: String,
/// Size in bytes.
pub size_bytes: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// The shop's rules for files on messages.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationAttachmentRules {
/// Whether messages may carry files at all.
pub enabled: bool,
/// Accepted file types: `pdf`, `png`, `jpeg`, `webp`, `text`.
#[serde(default)]
pub file_types: Vec<String>,
/// The largest file accepted, in megabytes.
pub max_file_megabytes: i32,
/// The most files one message may carry.
pub max_files: i32,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One of the buyer's conversations, as the buyer sees it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalConversation {
/// Conversation id.
pub id: String,
/// The record the conversation belongs to, on the buyer account.
#[serde(default)]
pub record: Option<String>,
/// The shop, as the message routes name it in `shop`.
pub shop: String,
/// The shop's name.
pub shop_name: String,
/// Whether the conversation belongs to test mode.
pub test_mode: bool,
/// `open` or `closed`.
pub status: String,
/// When the latest message was sent.
pub last_message_at: String,
/// Who sent it: `buyer` or `merchant`.
pub last_message_by: String,
/// Whether the buyer has messages they have not read.
pub unread: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// The buyer's conversations, the latest message first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalConversationList {
/// The conversations.
#[serde(default)]
pub data: Vec<BuyerPortalConversation>,
/// Whether conversations of records the buyer has not confirmed were
/// left out.
#[serde(default)]
pub unconfirmed_records: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One message, as the buyer sees it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalMessage {
/// Message id.
pub id: String,
/// `buyer` or `merchant`.
pub sender: String,
/// The first name of the team member who answered.
#[serde(default)]
pub sender_name: Option<String>,
/// The text. May be empty when the message carries files.
pub body: String,
/// The purchase the message is about.
#[serde(default)]
pub purchase: Option<String>,
/// The kind of that purchase.
#[serde(default)]
pub purchase_kind: Option<String>,
/// Files the message carries.
#[serde(default)]
pub attachments: Vec<BuyerConversationAttachment>,
/// When it was sent.
pub created_at: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A step of one of the buyer's cases, shown in the conversation.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerCaseUpdate {
/// The case id.
pub case: String,
/// `refund_request` or `dispute`.
pub kind: String,
/// The step.
pub event: BuyerCaseEvent,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// The conversation with one shop and its newest messages, oldest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalMessagePage {
/// The conversation, once one exists.
#[serde(default)]
pub conversation: Option<BuyerPortalConversation>,
/// The messages, oldest first.
#[serde(default)]
pub messages: Vec<BuyerPortalMessage>,
/// Whether older messages exist; page back with `before`.
#[serde(default)]
pub has_more: bool,
/// Steps of the buyer's cases at the shop.
#[serde(default)]
pub case_updates: Vec<BuyerCaseUpdate>,
/// The shop's rules for files on messages.
pub attachment_rules: BuyerConversationAttachmentRules,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One conversation in the team's inbox.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationSummary {
/// Conversation id.
pub id: String,
/// The shop.
pub profile_id: String,
/// The buyer.
pub customer_id: String,
/// The buyer's name.
#[serde(default)]
pub customer_name: Option<String>,
/// The buyer's email address.
#[serde(default)]
pub customer_email: Option<String>,
/// Whether the conversation belongs to test mode.
pub test_mode: bool,
/// `open` or `closed`.
pub status: String,
/// The team member it is assigned to.
#[serde(default)]
pub assigned_user_id: Option<String>,
/// That team member's name.
#[serde(default)]
pub assigned_user_name: Option<String>,
/// Whether it is assigned to the caller.
#[serde(default)]
pub assigned_to_me: bool,
/// When the latest message was sent.
pub last_message_at: String,
/// Who sent it: `buyer` or `merchant`.
pub last_message_by: String,
/// Whether the team has messages it has not read.
pub unread: bool,
/// When the conversation started.
pub created_at: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl fmt::Debug for BuyerConversationSummary {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("BuyerConversationSummary")
.field("id", &self.id)
.field("profile_id", &self.profile_id)
.field("customer_id", &self.customer_id)
.field(
"customer_name",
&self.customer_name.as_ref().map(|_| "<redacted>"),
)
.field(
"customer_email",
&self.customer_email.as_ref().map(|_| "<redacted>"),
)
.field("test_mode", &self.test_mode)
.field("status", &self.status)
.field("assigned_user_id", &self.assigned_user_id)
.field("assigned_to_me", &self.assigned_to_me)
.field("last_message_at", &self.last_message_at)
.field("last_message_by", &self.last_message_by)
.field("unread", &self.unread)
.field("created_at", &self.created_at)
.finish_non_exhaustive()
}
}
/// One page of the team's inbox, the latest message first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationList {
/// The conversations.
#[serde(default)]
pub data: Vec<BuyerConversationSummary>,
/// How many conversations match the filters, over all pages.
pub total_count: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One message, as the team sees it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationMessage {
/// Message id.
pub id: String,
/// `buyer` or `merchant`.
pub sender: String,
/// The first name the buyer sees for the team member who answered.
#[serde(default)]
pub sender_name: Option<String>,
/// The team member who answered.
#[serde(default)]
pub sender_user_id: Option<String>,
/// The text. May be empty when the message carries files.
pub body: String,
/// The purchase the message is about.
#[serde(default)]
pub purchase: Option<String>,
/// The kind of that purchase.
#[serde(default)]
pub purchase_kind: Option<String>,
/// Files the message carries.
#[serde(default)]
pub attachments: Vec<BuyerConversationAttachment>,
/// When it was sent.
pub created_at: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A team member's internal note. The buyer never sees one.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationNote {
/// Note id.
pub id: String,
/// The team member who wrote it.
pub author_user_id: String,
/// That team member's name.
#[serde(default)]
pub author_name: Option<String>,
/// The text.
pub body: String,
/// When it was written.
pub created_at: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A step of a case of the buyer at the shop, shown in the conversation.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationCaseUpdate {
/// `refund_request`, `dispute`, `paypal_case` or `subscription_dispute`.
pub source: String,
/// The id of the request or dispute.
pub source_id: String,
/// The payment it concerns.
#[serde(default)]
pub payment_id: Option<String>,
/// The step.
pub event: BuyerCaseEvent,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One conversation and its newest messages, oldest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerConversationDetail {
/// The conversation.
pub conversation: BuyerConversationSummary,
/// The messages, oldest first.
#[serde(default)]
pub messages: Vec<BuyerConversationMessage>,
/// Whether older messages exist; page back with `before`.
#[serde(default)]
pub has_more: bool,
/// Steps of the buyer's cases at the shop.
#[serde(default)]
pub case_updates: Vec<BuyerConversationCaseUpdate>,
/// The team's internal notes.
#[serde(default)]
pub notes: Vec<BuyerConversationNote>,
/// The shop's rules for files on answers.
pub attachment_rules: BuyerConversationAttachmentRules,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}