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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
use iso8601_timestamp::Timestamp;
use serde::Serialize;

use crate::{
    bot::FieldsBot,
    channel::{ChannelType, FieldsChannel},
    embed::SendableEmbed,
    emoji::EmojiParent,
    member::FieldsMember,
    message::{Interactions, Masquerade, MessageSort, Reply},
    mfa::MFAData,
    permission::{Override, Permission},
    report::{ReportStatus, ReportedContent},
    server::{Category, FieldsRole, FieldsServer, SystemMessageChannels},
    user::{FieldsUser, PartialUserProfile, UserStatus},
};

#[allow(dead_code)]
fn if_false(t: &bool) -> bool {
    !t
}

#[derive(Serialize, Debug, Clone, Default)]
pub struct SendMessagePayload {
    /// Message content to send
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<String>,
    /// Attachments to include in message
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attachments: Option<Vec<String>>,
    /// Messages to reply to
    #[serde(skip_serializing_if = "Option::is_none")]
    pub replies: Option<Vec<Reply>>,
    /// Embeds to include in message
    ///
    /// Text embed content contributes to the content length cap
    #[serde(skip_serializing_if = "Option::is_none")]
    pub embeds: Option<Vec<SendableEmbed>>,
    /// Masquerade to apply to this message
    #[serde(skip_serializing_if = "Option::is_none")]
    pub masquerade: Option<Masquerade>,
    /// Information about how this message should be interacted with
    #[serde(skip_serializing_if = "Option::is_none")]
    pub interactions: Option<Interactions>,
}

/// User data
#[derive(Serialize, Debug, Clone, Default)]
pub struct EditUserPayload {
    /// New user status
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<UserStatus>,
    /// New user profile data
    ///
    /// This is applied as a partial.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub profile: Option<PartialUserProfile>,
    /// Attachment ID for avatar
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar: Option<String>,
    /// Fields to remove from user object
    #[serde(skip_serializing_if = "Option::is_none")]
    pub remove: Option<Vec<FieldsUser>>,
}

/// Change username data
#[derive(Serialize, Debug, Clone)]
pub struct ChangeUsernamePayload {
    /// New username
    pub username: String,
    /// Current username password
    pub password: String,
}

/// Send friend request data
#[derive(Serialize, Debug, Clone)]
pub struct SendFriendRequestPayload {
    /// Friend's usernane
    pub username: String,
}

/// Edit channel data
#[derive(Serialize, Debug, Clone, Default)]
pub struct EditChannelPayload {
    /// Channel name
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Channel description
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// Group owner
    #[serde(skip_serializing_if = "Option::is_none")]
    pub owner: Option<String>,
    /// Icon attachment ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub icon: Option<String>,
    /// Whether this channel is age-restricted
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nsfw: Option<bool>,
    /// Fields to remove
    #[serde(skip_serializing_if = "Option::is_none")]
    pub remove: Option<Vec<FieldsChannel>>,
}

/// Set role permission payload data
#[derive(Serialize, Debug, Clone, Default)]
pub struct SetRolePermissionPayload {
    /// Representation of a single permission override
    pub permissions: Override,
}

/// Set role permission payload data
#[derive(Serialize, Debug, Clone)]
#[serde(untagged)]
pub enum SetDefaultPermissionPayload {
    Value {
        /// Permission values to set for members in a [Channel::Group]
        permissions: Permission,
    },
    Field {
        /// Allow / deny values to set for members in this [Channels::TextChannel] or [Channels::VoiceChannel]
        permissions: Override,
    },
}

/// Query parameters
#[derive(Serialize, Debug, Clone, Default)]
pub struct FetchMessagesPayload {
    /// Maximum number of messages to fetch
    ///
    /// For fetching nearby messages, this is `(limit + 1)`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Message id before which messages should be fetched
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// Message id after which messages should be fetched
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Message sort direction
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort: Option<MessageSort>,
    /// Message id to search around
    ///
    /// Specifying 'nearby' ignores 'before', 'after' and 'sort'.
    /// It will also take half of limit rounded as the limits to each side.
    /// It also fetches the message ID specified.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nearby: Option<String>,
    /// Whether to include user (and member, if server channel) objects
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_users: Option<bool>,
}

/// Search Parameters
#[derive(Serialize, Debug, Clone, Default)]
pub struct SearchForMessagesPayload {
    /// Full-text search query
    ///
    /// See [MongoDB documentation](https://docs.mongodb.com/manual/text-search/#-text-operator) for more information.
    pub query: String,

    /// Maximum number of messages to fetch
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Message id before which messages should be fetched
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// Message id after which messages should be fetched
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Message sort direction
    ///
    /// By default, it will be sorted by relevance.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort: Option<MessageSort>,
    /// Whether to include user (and member, if server channel) objects
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_users: Option<bool>,
}

/// Message details
#[derive(Serialize, Debug, Clone, Default)]
pub struct EditMessagePayload {
    /// New message content
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<String>,
    /// Embeds to include in the message
    #[serde(skip_serializing_if = "Option::is_none")]
    pub embeds: Option<Vec<SendableEmbed>>,
}

/// Search parameters
#[derive(Serialize, Debug, Clone)]
pub struct BulkDeleteMessagesPayload {
    /// Message IDs
    pub ids: Vec<String>,
}

/// Reactions remove options
#[derive(Serialize, Debug, Clone, Default)]
pub struct RemoveReactionToMessagePayload {
    /// Remove a specific user's reaction
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_id: Option<String>,
    /// Remove all reactions
    #[serde(skip_serializing_if = "Option::is_none")]
    pub remove_all: Option<bool>,
}

/// Group create data
#[derive(Serialize, Debug, Clone, Default)]
pub struct CreateGroupPayload {
    /// Group name
    name: String,
    /// Group description
    description: Option<String>,
    /// Array of user IDs to add to the group
    ///
    /// Must be friends with these users.
    users: Vec<String>,
    /// Whether this group is age-restricted
    #[serde(skip_serializing_if = "Option::is_none")]
    nsfw: Option<bool>,
}

/// Bot create data
#[derive(Serialize, Debug, Clone)]
pub struct CreateBotPayload {
    /// Bot username
    name: String,
}

/// Bot invite data
#[derive(Serialize, Debug, Clone)]
#[serde(untagged)]
pub enum InviteBotPayload {
    /// Invite to a server
    Server {
        /// Server Id
        server: String,
    },
    /// Invite to a group
    Group {
        /// Group Id
        group: String,
    },
}

/// Bot edit data
#[derive(Serialize, Debug, Clone, Default)]
pub struct EditBotPayload {
    /// Bot username
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Whether the bot can be added by anyone
    #[serde(skip_serializing_if = "Option::is_none")]
    pub public: Option<bool>,
    /// Whether analytics should be gathered for this bot
    ///
    /// Must be enabled in order to show up on [Revolt Discover](https://rvlt.gg).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub analytics: Option<bool>,
    /// Interactions URL
    #[serde(skip_serializing_if = "Option::is_none")]
    pub interactions_url: Option<String>,
    /// Fields to remove from bot object
    #[serde(skip_serializing_if = "Option::is_none")]
    pub remove: Option<Vec<FieldsBot>>,
}

/// Create server data
#[derive(Serialize, Debug, Clone, Default)]
pub struct CreateServerPayload {
    /// Server name
    pub name: String,
    /// Server description
    pub description: Option<String>,
    /// Whether this server is age-restricted
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nsfw: Option<bool>,
}

/// Edit server data
#[derive(Serialize, Debug, Clone, Default)]
pub struct EditServerPayload {
    /// Server name
    pub name: Option<String>,
    /// Server description
    pub description: Option<String>,

    /// Attachment Id for icon
    pub icon: Option<String>,
    /// Attachment Id for banner
    pub banner: Option<String>,

    /// Category structure for server
    pub categories: Option<Vec<Category>>,
    /// System message configuration
    pub system_messages: Option<SystemMessageChannels>,

    // Whether this server is age-restricted
    pub nsfw: Option<bool>,
    /// Whether this server is public and should show up on [Revolt Discover](https://rvlt.gg)
    pub discoverable: Option<bool>,
    /// Whether analytics should be collected for this server
    ///
    /// Must be enabled in order to show up on [Revolt Discover](https://rvlt.gg).
    pub analytics: Option<bool>,

    /// Fields to remove from server object
    pub remove: Option<Vec<FieldsServer>>,
}

/// Create channel data
#[derive(Serialize, Debug, Clone, Default)]
pub struct CreateChannelPayload {
    /// Channel type
    #[serde(rename = "type", default = "ChannelType::default")]
    pub channel_type: ChannelType,
    /// Channel name
    pub name: String,
    /// Channel description
    pub description: Option<String>,
    /// Whether this channel is age restricted
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nsfw: Option<bool>,
}

/// Create emoji data
#[derive(Serialize, Debug, Clone)]
pub struct CreateEmojiPayload {
    /// Server name
    pub name: String,
    /// Parent information
    pub parent: EmojiParent,
    /// Whether the emoji is mature
    pub nsfw: bool,
}

/// Fetch settings data
#[derive(Serialize, Debug, Clone)]
pub struct FetchSettingsPayload {
    /// Keys to fetch
    pub keys: Vec<String>,
}

/// Web push subscription data
#[derive(Serialize, Debug, Clone)]
pub struct PushSubscribePayload {
    pub endpoint: String,
    pub p256dh: String,
    pub auth: String,
}

/// Create role data
#[derive(Serialize, Debug, Clone, Default)]
pub struct CreateRolePayload {
    /// Role name
    pub name: String,
    /// Ranking position
    ///
    /// Smaller values take priority.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rank: Option<i64>,
}

/// Edit role data
#[derive(Serialize, Debug, Clone, Default)]
pub struct EditRolePayload {
    /// Role name
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Role colour
    #[serde(skip_serializing_if = "Option::is_none")]
    pub colour: Option<String>,
    /// Whether this role should be displayed separately
    #[serde(skip_serializing_if = "Option::is_none")]
    pub hoist: Option<bool>,
    /// Ranking position
    ///
    /// Smaller values take priority.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rank: Option<i64>,
    /// Fields to remove from role object
    #[serde(skip_serializing_if = "Option::is_none")]
    pub remove: Option<Vec<FieldsRole>>,
}

/// Server role permission value
#[derive(Serialize, Debug, Clone, Default)]
pub struct SetServerRolePermissionPayload {
    /// Allow / deny values for the role in this server.
    pub permissions: Override,
}

/// Default server role permission value
#[derive(Serialize, Debug, Clone, Default)]
pub struct SetDefaultRolePermissionPayload {
    /// Allow / deny values for the role in this server.
    pub permissions: Override,
}

/// Members query options
#[derive(Serialize, Debug, Clone, Default)]
pub struct FetchMembersPayload {
    /// Whether to exclude offline users
    #[serde(skip_serializing_if = "if_false")]
    pub exclude_offline: bool,
}

/// Member edit data
#[derive(Serialize, Debug, Clone, Default)]
pub struct EditMemberPayload {
    /// Member nickname
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nickname: Option<String>,
    /// Attachment Id to set for avatar
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar: Option<String>,
    /// Array of role ids
    #[serde(skip_serializing_if = "Option::is_none")]
    pub roles: Option<Vec<String>>,
    /// Timestamp this member is timed out until
    #[serde(skip_serializing_if = "Option::is_none")]
    pub timeout: Option<Timestamp>,
    /// Fields to remove from channel object
    #[serde(skip_serializing_if = "Option::is_none")]
    pub remove: Option<Vec<FieldsMember>>,
}

/// Ban information
#[derive(Serialize, Debug, Clone, Default)]
pub struct BanUserPayload {
    /// Ban reason
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason: Option<String>,
}

/// New account data
#[derive(Serialize, Debug, Clone, Default)]
pub struct CreateAccountPayload {
    /// Valid email address
    pub email: String,
    /// Password
    pub password: String,
    /// Invite code
    #[serde(skip_serializing_if = "Option::is_none")]
    pub invite: Option<String>,
    /// Captcha verification code
    #[serde(skip_serializing_if = "Option::is_none")]
    pub captcha: Option<String>,
}

/// Resend information
#[derive(Serialize, Debug, Clone, Default)]
pub struct ResendVerificationPayload {
    /// Email associated with the account
    pub email: String,
    /// Captcha verification code
    #[serde(skip_serializing_if = "Option::is_none")]
    pub captcha: Option<String>,
}

/// Account deletion data
#[derive(Serialize, Debug, Clone)]
pub struct ConfirmAccountDeletionPayload {
    /// Deletion token
    pub token: String,
}

/// Change password data
#[derive(Serialize, Debug, Clone)]
pub struct ChangePasswordPayload {
    /// New password
    pub password: String,
    /// Current password
    pub current_password: String,
}

/// Change email data
#[derive(Serialize, Debug, Clone)]
pub struct ChangeEmailPayload {
    /// Valid email address
    pub email: String,
    /// Current password
    pub current_password: String,
}

/// Reset password information
#[derive(Serialize, Debug, Clone)]
pub struct SendPasswordResetPayload {
    /// Email associated with the account
    pub email: String,
    /// Captcha verification code
    #[serde(skip_serializing_if = "Option::is_none")]
    pub captcha: Option<String>,
}

/// Password reset data
#[derive(Serialize, Debug, Clone)]
pub struct PasswordResetPayload {
    /// Reset token
    pub token: String,
    /// New password
    pub password: String,
    /// Whether to logout all sessions
    #[serde(default)]
    pub remove_sessions: bool,
}

/// New user data
#[derive(Serialize, Debug, Clone)]
pub struct CompleteOnboardingPayload {
    /// New username which will be used to identify the user on the platform
    pub username: String,
}

/// Edit report data
#[derive(Serialize, Debug, Clone)]
pub struct EditReportPayload {
    /// New report status
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<ReportStatus>,
    /// Report notes
    #[serde(skip_serializing_if = "Option::is_none")]
    pub notes: Option<String>,
}

/// Report data
#[derive(Serialize, Debug, Clone)]
pub struct ReportContentPayload {
    /// Content being reported
    pub content: ReportedContent,
    /// Additional report description
    #[serde(skip_serializing_if = "Option::is_none")]
    pub additional_context: Option<String>,
}

/// Login data
#[derive(Serialize, Debug, Clone)]
#[serde(untagged)]
pub enum LoginPayload {
    Email {
        /// Email
        email: String,
        /// Password
        password: String,
        /// Friendly name used for the session
        #[serde(skip_serializing_if = "Option::is_none")]
        friendly_name: Option<String>,
    },
    MFA {
        /// Unvalidated or authorised MFA ticket
        ///
        /// Used to resolve the correct account
        mfa_ticket: String,
        /// Valid MFA response
        ///
        /// This will take precedence over the `password` field where applicable
        #[serde(skip_serializing_if = "Option::is_none")]
        mfa_response: Option<MFAData>,
        /// Friendly name used for the session
        #[serde(skip_serializing_if = "Option::is_none")]
        friendly_name: Option<String>,
    },
}

/// Sessions clear data
#[derive(Serialize, Debug, Clone, Default)]
pub struct DeleteAllSessionsPayload {
    #[serde(skip_serializing_if = "if_false")]
    pub revoke_self: bool,
}

/// Session edit data
#[derive(Serialize, Debug, Clone)]
pub struct EditSessionPayload {
    /// Session friendly name
    pub friendly_name: String,
}

/// MFA ticket create data
pub type CreateMFATicketPayload = MFAData;

/// TOTP secret generate data
pub type EnableTOTP2FAPayload = MFAData;