twilight_model/guild/audit_log/
change.rs

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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
use super::change_key::AuditLogChangeKey;
use crate::{
    application::command::permissions::GuildCommandPermissions,
    channel::{
        message::sticker::StickerFormatType, permission_overwrite::PermissionOverwrite,
        stage_instance::PrivacyLevel, thread::AutoArchiveDuration,
    },
    guild::{
        DefaultMessageNotificationLevel, ExplicitContentFilter, MfaLevel, NSFWLevel, Permissions,
        VerificationLevel,
    },
    id::{
        marker::{
            ApplicationMarker, ChannelMarker, GenericMarker, GuildMarker, RoleMarker, UserMarker,
        },
        Id,
    },
    util::{ImageHash, Timestamp},
};
use serde::{Deserialize, Serialize};

/// Minimal amount of information about an affected [role].
///
/// The following [`AuditLogChange`]s include this information:
///
/// - [`AuditLogChange::RoleAdded`]
/// - [`AuditLogChange::RoleRemoved`]
///
/// [role]: super::super::Role
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct AffectedRole {
    /// ID of the role.
    pub id: Id<RoleMarker>,
    /// Name of the role.
    pub name: String,
}

/// Value of a change which may be one of multiple types.
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(untagged)]
pub enum AuditLogChangeTypeValue {
    /// Value is an unsigned integer.
    Unsigned(u64),
    /// Value is a string.
    String(String),
}

/// Individual change within an [`AuditLogEntry`].
///
/// [`AuditLogEntry`]: super::AuditLogEntry
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[non_exhaustive]
#[serde(rename_all = "snake_case", tag = "key")]
pub enum AuditLogChange {
    /// AFK channel ID was changed.
    AfkChannelId {
        /// New ID of the AFK channel.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Id<ChannelMarker>>,
        /// Old ID of the AFK channel.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Id<ChannelMarker>>,
    },
    /// Timeout to cause a user to be moved to an AFK voice channel.
    AfkTimeout {
        /// New timeout, in seconds.
        #[serde(rename = "new_value")]
        new: u64,
        /// Old timeout, in seconds.
        #[serde(rename = "old_value")]
        old: u64,
    },
    /// Allowed permissions of a permission overwrite target.
    Allow {
        /// New allowed permissions value.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Permissions>,
        /// Old allowed permissions value.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Permissions>,
    },
    /// ID of an application.
    ApplicationId {
        /// Application's ID.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Id<ApplicationMarker>>,
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Id<ApplicationMarker>>,
    },
    /// Thread is now archived/unarchived.
    Archived {
        /// Whether the thread is archived.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// Asset of a sticker.
    Asset {
        /// Empty string.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Auto archive duration of a thread changed.
    AutoArchiveDuration {
        /// New auto archive duration.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<AutoArchiveDuration>,
        /// Old auto archive duration.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<AutoArchiveDuration>,
    },
    /// Availability of a sticker.
    Available {
        /// New availability.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Old availability.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// Hash of an avatar.
    AvatarHash {
        /// New hash of an avatar.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<ImageHash>,
        /// Old hash of an avatar.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<ImageHash>,
    },
    /// Hash of a guild banner.
    BannerHash {
        /// New hash of a guild's banner.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<ImageHash>,
        /// Old hash of a guild's banner.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<ImageHash>,
    },
    /// Bitrate of an audio channel.
    Bitrate {
        /// New bitrate.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Old bitrate.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// Channel for an invite code.
    ChannelId {
        /// New invite's channel.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Id<ChannelMarker>>,
        /// Old invite's channel.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Id<ChannelMarker>>,
    },
    /// Code of an invite.
    Code {
        /// New invite's code.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Color of a role.
    Color {
        /// New role color.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Old role color.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// Permissions for a command were updated
    CommandId {
        /// New command permissions.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<GuildCommandPermissions>,
        /// Old command permissions.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<GuildCommandPermissions>,
    },
    /// Member timeout state changed.
    CommunicationDisabledUntil {
        /// New timeout timestamp.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Timestamp>,
        /// Old timeout timestamp.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Timestamp>,
    },
    /// Whether a member is guild deafened.
    Deaf {
        /// Whether a member is now guild deafened.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// default auto archive duration for newly created threads changed.
    DefaultAutoArchiveDuration {
        /// New auto archive duration.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<AutoArchiveDuration>,
        /// Old auto archive duration.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<AutoArchiveDuration>,
    },
    /// Default message notification level for a guild.
    DefaultMessageNotifications {
        /// New default message notification level.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<DefaultMessageNotificationLevel>,
        /// Old default message notification level.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<DefaultMessageNotificationLevel>,
    },
    /// Denied permissions of a permission overwrite target.
    Deny {
        /// New denied permissions level.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Permissions>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Permissions>,
    },
    /// Description of a guild or sticker.
    Description {
        /// New guild description.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        /// Old guild description.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Hash of a guild's discovery splash.
    DiscoverySplashHash {
        /// New discovery splash hash.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<ImageHash>,
        /// Old discovery splash hash.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<ImageHash>,
    },
    /// Whether emoticons are enabled.
    EnableEmoticons {
        /// Whether emoticons are now enabled.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Whether emoticons were enabled.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// Entity type of guild scheduled event was changed.
    EntityType {
        /// New entity type.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// Behavior of the expiration of an integration.
    ExpireBehavior {
        /// New expiration behavior.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// Grace period of the expiration of an integration.
    ExpireGracePeriod {
        /// New expiration grace period.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// Explicit content filter level of a guild.
    ExplicitContentFilter {
        /// New explicit content filter level.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<ExplicitContentFilter>,
        /// Old explicit content filter level.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<ExplicitContentFilter>,
    },
    /// Format type of a sticker.
    FormatType {
        /// New format type of a sticker.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<StickerFormatType>,
        /// Old format type of a sticker.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<StickerFormatType>,
    },
    /// Guild that a sticker is in.
    GuildId {
        /// New guild that a sticker is in.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Id<GuildMarker>>,
        /// Old guild that a sticker is in.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Id<GuildMarker>>,
    },
    /// Whether a role is hoisted.
    Hoist {
        /// Whether a role is now hoisted.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Whether a role was hoisted.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// Hash of a guild icon.
    IconHash {
        /// New hash of a guild's icon.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<ImageHash>,
        /// Old hash of a guild's icon.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<ImageHash>,
    },
    /// ID of an entity.
    Id {
        /// New entity's ID.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Id<GenericMarker>>,
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Id<GenericMarker>>,
    },
    /// Hash of a guild scheduled event cover.
    ImageHash {
        /// New hash of a guild's icon.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<ImageHash>,
        /// Old hash of a guild's icon.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<ImageHash>,
    },
    /// Invitable state of a private thread.
    Invitable {
        /// New threads invitable state.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Old threads invitable state.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// ID of the user who created an invite.
    InviterId {
        /// User ID.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Id<UserMarker>>,
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Id<UserMarker>>,
    },
    /// Location for a scheduled event changed.
    ///
    /// Can be an [`Id<ChannelMarker>`] or a [`String`].
    Location {
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Thread was locked or unlocked.
    Locked {
        /// Whether the thread is now locked.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// Maximum age of an invite.
    MaxAge {
        /// New maximum age.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// Maximum uses of an invite.
    MaxUses {
        /// New maximum uses.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// Whether a role can be mentioned in a message.
    Mentionable {
        /// Whether a role is now mentionable.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Whether a role was mentionable.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// Multi-Factor Authentication level required of a guild's moderators.
    MfaLevel {
        /// New MFA level of a guild.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<MfaLevel>,
        /// Old MFA level of a guild.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<MfaLevel>,
    },
    /// Whether a user is guild muted.
    Mute {
        /// Whether a member is now muted.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Whether a member was muted.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// Name of an entity such as a channel or role.
    Name {
        /// New entity name.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        /// Old entity name.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Nickname of a member.
    Nick {
        /// New member nickname.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        /// Old member nickname.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Whether a channel is NSFW.
    Nsfw {
        /// New state.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// NSFW level of a guild.
    NsfwLevel {
        /// New NSFW level.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<NSFWLevel>,
        /// Old NSFW level.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<NSFWLevel>,
    },
    /// ID of the owner of a guild.
    OwnerId {
        /// New owner's ID.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Id<UserMarker>>,
        /// Old owner's ID.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Id<UserMarker>>,
    },
    /// Permission overwrites on a channel changed.
    PermissionOverwrites {
        /// New set of overwrites.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Vec<PermissionOverwrite>>,
        /// Old set of overwrites.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Vec<PermissionOverwrite>>,
    },
    /// Default permissions of a role.
    Permissions {
        /// New set of permissions.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Permissions>,
        /// Old set of permissions.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Permissions>,
    },
    /// Position of an entity such as a channel or role.
    Position {
        /// New position value.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Old position value.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// Preferred locale of a guild.
    PreferredLocale {
        /// New preferred locale.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        /// Old preferred locale.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Privacy level of a stage instance.
    PrivacyLevel {
        /// New privacy level.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<PrivacyLevel>,
        /// Old privacy level.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<PrivacyLevel>,
    },
    /// Number of days' worth of inactivity for a guild prune.
    PruneDeleteDays {
        /// Number of days.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// ID of a guild's public updates channel.
    PublicUpdatesChannelId {
        /// New public updates channel ID.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Id<ChannelMarker>>,
        /// Old public updates channel ID.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Id<ChannelMarker>>,
    },
    /// Ratelimit per user in a textual channel.
    RateLimitPerUser {
        /// New ratelimit, in seconds.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Old ratelimit, in seconds.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// Region of a guild changed.
    Region {
        /// New region.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Role was added to a user.
    #[serde(rename = "$add")]
    RoleAdded {
        /// Minimal information about a added role.
        #[serde(default, rename = "new_value", skip_serializing_if = "Vec::is_empty")]
        new: Vec<AffectedRole>,
        /// Previous state, if any.
        #[serde(default, rename = "old_value", skip_serializing_if = "Vec::is_empty")]
        old: Vec<AffectedRole>,
    },
    /// Role was removed from a user.
    #[serde(rename = "$remove")]
    RoleRemoved {
        /// Minimal information about a removed role.
        #[serde(default, rename = "new_value", skip_serializing_if = "Vec::is_empty")]
        new: Vec<AffectedRole>,
        /// Previous state, if any.
        #[serde(default, rename = "old_value", skip_serializing_if = "Vec::is_empty")]
        old: Vec<AffectedRole>,
    },
    /// Guild's rules channel.
    RulesChannelId {
        /// New rules channel.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Id<ChannelMarker>>,
        /// Old rules channel.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Id<ChannelMarker>>,
    },
    /// Hash of a guild's splash.
    SplashHash {
        /// Old hash of a guild's splash.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<ImageHash>,
        /// New hash of a guild's splash.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<ImageHash>,
    },
    /// Status of guild scheduled event was changed.
    Status {
        /// New status.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// ID of guild's system channel.
    SystemChannelId {
        /// New system channel ID.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Id<ChannelMarker>>,
        /// Old system channel ID.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Id<ChannelMarker>>,
    },
    /// Related emoji of a sticker.
    Tags {
        /// New related emoji of a sticker.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        /// Old related emoji of a sticker.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Whether an invite is temporary.
    Temporary {
        /// New temporary state.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// Topic of a textual channel.
    Topic {
        /// New topic.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        /// Old topic.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Type of a created entity.
    ///
    /// The value of a type is dependent on the entity. For example, a channel's
    /// type may be an integer while an integration's may be a string.
    Type {
        /// New target type.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<AuditLogChangeTypeValue>,
        /// Old target type.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<AuditLogChangeTypeValue>,
    },
    /// Unicode emoji of a role icon changed.
    UnicodeEmoji {
        /// New unicode emoji.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        /// Old target type.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Maximum number of users in a voice channel.
    UserLimit {
        /// New limit.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Old limit.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// Number of uses of an invite.
    Uses {
        /// Number of uses.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<u64>,
        /// Previous state, if any.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<u64>,
    },
    /// Code of a guild's vanity invite.
    VanityUrlCode {
        /// New vanity URL code.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<String>,
        /// Old vanity URL code.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<String>,
    },
    /// Required verification level of new members in a guild.
    VerificationLevel {
        /// New verification level.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<VerificationLevel>,
        /// Old verification level.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<VerificationLevel>,
    },
    /// Channel ID of a widget.
    WidgetChannelId {
        /// New channel ID.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<Id<ChannelMarker>>,
        /// Old channel ID.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<Id<ChannelMarker>>,
    },
    /// Whether a widget is enabled.
    WidgetEnabled {
        /// New state of a widget being enabled.
        #[serde(rename = "new_value", skip_serializing_if = "Option::is_none")]
        new: Option<bool>,
        /// Old state of a widget being enabled.
        #[serde(rename = "old_value", skip_serializing_if = "Option::is_none")]
        old: Option<bool>,
    },
    /// Other type of change not covered by other variants.
    #[serde(other)]
    Other,
}

impl AuditLogChange {
    /// Key of an audit log change.
    ///
    /// This may return no key if the variant is [`Other`].
    ///
    /// # Examples
    ///
    /// Check the key of a [`Uses`] change:
    ///
    /// ```
    /// use twilight_model::guild::audit_log::{AuditLogChange, AuditLogChangeKey};
    ///
    /// let change = AuditLogChange::UserLimit {
    ///     new: Some(6),
    ///     old: Some(3),
    /// };
    ///
    /// assert_eq!(Some(AuditLogChangeKey::UserLimit), change.key());
    /// ```
    ///
    /// [`Other`]: Self::Other
    /// [`Uses`]: Self::Uses
    pub const fn key(&self) -> Option<AuditLogChangeKey> {
        Some(match self {
            Self::AfkChannelId { .. } => AuditLogChangeKey::AfkChannelId,
            Self::AfkTimeout { .. } => AuditLogChangeKey::AfkTimeout,
            Self::Allow { .. } => AuditLogChangeKey::Allow,
            Self::ApplicationId { .. } => AuditLogChangeKey::ApplicationId,
            Self::Archived { .. } => AuditLogChangeKey::Archived,
            Self::Asset { .. } => AuditLogChangeKey::Asset,
            Self::AutoArchiveDuration { .. } => AuditLogChangeKey::AutoArchiveDuration,
            Self::Available { .. } => AuditLogChangeKey::Available,
            Self::AvatarHash { .. } => AuditLogChangeKey::AvatarHash,
            Self::BannerHash { .. } => AuditLogChangeKey::BannerHash,
            Self::Bitrate { .. } => AuditLogChangeKey::Bitrate,
            Self::ChannelId { .. } => AuditLogChangeKey::ChannelId,
            Self::Code { .. } => AuditLogChangeKey::Code,
            Self::Color { .. } => AuditLogChangeKey::Color,
            Self::CommandId { .. } => AuditLogChangeKey::CommandId,
            Self::CommunicationDisabledUntil { .. } => {
                AuditLogChangeKey::CommunicationDisabledUntil
            }
            Self::Deaf { .. } => AuditLogChangeKey::Deaf,
            Self::DefaultAutoArchiveDuration { .. } => {
                AuditLogChangeKey::DefaultAutoArchiveDuration
            }
            Self::DefaultMessageNotifications { .. } => {
                AuditLogChangeKey::DefaultMessageNotifications
            }
            Self::Deny { .. } => AuditLogChangeKey::Deny,
            Self::Description { .. } => AuditLogChangeKey::Description,
            Self::DiscoverySplashHash { .. } => AuditLogChangeKey::DiscoverySplashHash,
            Self::EnableEmoticons { .. } => AuditLogChangeKey::EnableEmoticons,
            Self::EntityType { .. } => AuditLogChangeKey::EntityType,
            Self::ExpireBehavior { .. } => AuditLogChangeKey::ExpireBehavior,
            Self::ExpireGracePeriod { .. } => AuditLogChangeKey::ExpireGracePeriod,
            Self::ExplicitContentFilter { .. } => AuditLogChangeKey::ExplicitContentFilter,
            Self::FormatType { .. } => AuditLogChangeKey::FormatType,
            Self::GuildId { .. } => AuditLogChangeKey::GuildId,
            Self::Hoist { .. } => AuditLogChangeKey::Hoist,
            Self::IconHash { .. } => AuditLogChangeKey::IconHash,
            Self::Id { .. } => AuditLogChangeKey::Id,
            Self::ImageHash { .. } => AuditLogChangeKey::ImageHash,
            Self::Invitable { .. } => AuditLogChangeKey::Invitable,
            Self::InviterId { .. } => AuditLogChangeKey::InviterId,
            Self::Location { .. } => AuditLogChangeKey::Location,
            Self::Locked { .. } => AuditLogChangeKey::Locked,
            Self::MaxAge { .. } => AuditLogChangeKey::MaxAge,
            Self::MaxUses { .. } => AuditLogChangeKey::MaxUses,
            Self::Mentionable { .. } => AuditLogChangeKey::Mentionable,
            Self::MfaLevel { .. } => AuditLogChangeKey::MfaLevel,
            Self::Mute { .. } => AuditLogChangeKey::Mute,
            Self::Name { .. } => AuditLogChangeKey::Name,
            Self::Nick { .. } => AuditLogChangeKey::Nick,
            Self::Nsfw { .. } => AuditLogChangeKey::Nsfw,
            Self::NsfwLevel { .. } => AuditLogChangeKey::NsfwLevel,
            Self::OwnerId { .. } => AuditLogChangeKey::OwnerId,
            Self::PermissionOverwrites { .. } => AuditLogChangeKey::PermissionOverwrites,
            Self::Permissions { .. } => AuditLogChangeKey::Permissions,
            Self::Position { .. } => AuditLogChangeKey::Position,
            Self::PreferredLocale { .. } => AuditLogChangeKey::PreferredLocale,
            Self::PrivacyLevel { .. } => AuditLogChangeKey::PrivacyLevel,
            Self::PruneDeleteDays { .. } => AuditLogChangeKey::PruneDeleteDays,
            Self::PublicUpdatesChannelId { .. } => AuditLogChangeKey::PublicUpdatesChannelId,
            Self::RateLimitPerUser { .. } => AuditLogChangeKey::RateLimitPerUser,
            Self::Region { .. } => AuditLogChangeKey::Region,
            Self::RoleAdded { .. } => AuditLogChangeKey::RoleAdded,
            Self::RoleRemoved { .. } => AuditLogChangeKey::RoleRemoved,
            Self::RulesChannelId { .. } => AuditLogChangeKey::RulesChannelId,
            Self::SplashHash { .. } => AuditLogChangeKey::SplashHash,
            Self::Status { .. } => AuditLogChangeKey::Status,
            Self::SystemChannelId { .. } => AuditLogChangeKey::SystemChannelId,
            Self::Tags { .. } => AuditLogChangeKey::Tags,
            Self::Temporary { .. } => AuditLogChangeKey::Temporary,
            Self::Topic { .. } => AuditLogChangeKey::Topic,
            Self::Type { .. } => AuditLogChangeKey::Type,
            Self::UnicodeEmoji { .. } => AuditLogChangeKey::UnicodeEmoji,
            Self::UserLimit { .. } => AuditLogChangeKey::UserLimit,
            Self::Uses { .. } => AuditLogChangeKey::Uses,
            Self::VanityUrlCode { .. } => AuditLogChangeKey::VanityUrlCode,
            Self::VerificationLevel { .. } => AuditLogChangeKey::VerificationLevel,
            Self::WidgetChannelId { .. } => AuditLogChangeKey::WidgetChannelId,
            Self::WidgetEnabled { .. } => AuditLogChangeKey::WidgetEnabled,
            Self::Other => return None,
        })
    }
}

#[cfg(test)]
mod tests {
    use super::{super::AuditLogChangeKey, AffectedRole, AuditLogChange, AuditLogChangeTypeValue};
    use crate::{channel::ChannelType, guild::Permissions, id::Id};
    use serde::{Deserialize, Serialize};
    use serde_test::Token;
    use static_assertions::{assert_fields, assert_impl_all};
    use std::{fmt::Debug, hash::Hash};

    assert_fields!(AffectedRole: id, name);
    assert_fields!(AuditLogChange::AfkChannelId: new, old);
    assert_fields!(AuditLogChange::AfkTimeout: new, old);
    assert_fields!(AuditLogChange::Allow: new);
    assert_fields!(AuditLogChange::ApplicationId: new);
    assert_fields!(AuditLogChange::AvatarHash: new, old);
    assert_fields!(AuditLogChange::BannerHash: new, old);
    assert_fields!(AuditLogChange::Bitrate: new, old);
    assert_fields!(AuditLogChange::ChannelId: new);
    assert_fields!(AuditLogChange::Code: new);
    assert_fields!(AuditLogChange::Color: new, old);
    assert_fields!(AuditLogChange::CommandId: new, old);
    assert_fields!(AuditLogChange::CommunicationDisabledUntil: new, old);
    assert_fields!(AuditLogChange::Deaf: new, old);
    assert_fields!(AuditLogChange::DefaultMessageNotifications: new, old);
    assert_fields!(AuditLogChange::Deny: new);
    assert_fields!(AuditLogChange::Description: new, old);
    assert_fields!(AuditLogChange::DiscoverySplashHash: new, old);
    assert_fields!(AuditLogChange::EnableEmoticons: new, old);
    assert_fields!(AuditLogChange::ExpireBehavior: new);
    assert_fields!(AuditLogChange::ExpireGracePeriod: new);
    assert_fields!(AuditLogChange::ExplicitContentFilter: new, old);
    assert_fields!(AuditLogChange::Hoist: new, old);
    assert_fields!(AuditLogChange::IconHash: new, old);
    assert_fields!(AuditLogChange::Id: new);
    assert_fields!(AuditLogChange::ImageHash: new, old);
    assert_fields!(AuditLogChange::Invitable: new, old);
    assert_fields!(AuditLogChange::InviterId: new);
    assert_fields!(AuditLogChange::MaxAge: new);
    assert_fields!(AuditLogChange::MaxUses: new);
    assert_fields!(AuditLogChange::Mentionable: new, old);
    assert_fields!(AuditLogChange::MfaLevel: new, old);
    assert_fields!(AuditLogChange::Mute: new, old);
    assert_fields!(AuditLogChange::Name: new, old);
    assert_fields!(AuditLogChange::Nick: new, old);
    assert_fields!(AuditLogChange::NsfwLevel: new, old);
    assert_fields!(AuditLogChange::OwnerId: new, old);
    assert_fields!(AuditLogChange::Permissions: new, old);
    assert_fields!(AuditLogChange::PrivacyLevel: new, old);
    assert_fields!(AuditLogChange::Position: new, old);
    assert_fields!(AuditLogChange::PreferredLocale: new, old);
    assert_fields!(AuditLogChange::PruneDeleteDays: new);
    assert_fields!(AuditLogChange::PublicUpdatesChannelId: new, old);
    assert_fields!(AuditLogChange::RateLimitPerUser: new, old);
    assert_fields!(AuditLogChange::RoleAdded: new);
    assert_fields!(AuditLogChange::RoleRemoved: new);
    assert_fields!(AuditLogChange::RulesChannelId: new, old);
    assert_fields!(AuditLogChange::SplashHash: new, old);
    assert_fields!(AuditLogChange::SystemChannelId: new, old);
    assert_fields!(AuditLogChange::Temporary: new);
    assert_fields!(AuditLogChange::Topic: new);
    assert_fields!(AuditLogChange::Type: new);
    assert_fields!(AuditLogChange::Uses: new);
    assert_fields!(AuditLogChange::UserLimit: new, old);
    assert_fields!(AuditLogChange::VanityUrlCode: new, old);
    assert_fields!(AuditLogChange::VerificationLevel: new, old);
    assert_fields!(AuditLogChange::WidgetChannelId: new, old);
    assert_fields!(AuditLogChange::WidgetEnabled: new, old);
    assert_impl_all!(
        AffectedRole: Clone,
        Debug,
        Deserialize<'static>,
        Eq,
        Hash,
        PartialEq,
        Send,
        Serialize,
        Sync
    );
    assert_impl_all!(
        AuditLogChange: Clone,
        Debug,
        Deserialize<'static>,
        Eq,
        Hash,
        PartialEq,
        Send,
        Serialize,
        Sync
    );
    assert_impl_all!(
        AuditLogChangeTypeValue: Clone,
        Debug,
        Deserialize<'static>,
        Eq,
        Hash,
        PartialEq,
        Send,
        Serialize,
        Sync
    );

    #[test]
    fn afk_channel_id() {
        let value = AuditLogChange::AfkChannelId {
            new: Some(Id::new(1)),
            old: None,
        };

        assert_eq!(Some(AuditLogChangeKey::AfkChannelId), value.key());

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "AuditLogChange",
                    len: 2,
                },
                Token::String("key"),
                Token::String("afk_channel_id"),
                Token::String("new_value"),
                Token::Some,
                Token::NewtypeStruct { name: "Id" },
                Token::String("1"),
                Token::StructEnd,
            ],
        );
    }

    #[test]
    fn permissions() {
        let old: Permissions = Permissions::SEND_MESSAGES;
        let new: Permissions = old | Permissions::EMBED_LINKS;

        let value = AuditLogChange::Permissions {
            new: Some(new),
            old: Some(old),
        };

        assert_eq!(Some(AuditLogChangeKey::Permissions), value.key());

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "AuditLogChange",
                    len: 3,
                },
                Token::String("key"),
                Token::String("permissions"),
                Token::String("new_value"),
                Token::Some,
                Token::Str("18432"),
                Token::String("old_value"),
                Token::Some,
                Token::Str("2048"),
                Token::StructEnd,
            ],
        );
    }

    #[test]
    fn channel_type() {
        let value = AuditLogChange::Type {
            new: Some(AuditLogChangeTypeValue::Unsigned(u64::from(u8::from(
                ChannelType::PrivateThread,
            )))),
            old: None,
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "AuditLogChange",
                    len: 2,
                },
                Token::String("key"),
                Token::Str("type"),
                Token::String("new_value"),
                Token::Some,
                Token::U64(u64::from(u8::from(ChannelType::PrivateThread))),
                Token::StructEnd,
            ],
        );
    }

    #[test]
    fn integration_type() {
        let value = AuditLogChange::Type {
            new: Some(AuditLogChangeTypeValue::String("discord".to_owned())),
            old: None,
        };

        serde_test::assert_tokens(
            &value,
            &[
                Token::Struct {
                    name: "AuditLogChange",
                    len: 2,
                },
                Token::String("key"),
                Token::Str("type"),
                Token::String("new_value"),
                Token::Some,
                Token::Str("discord"),
                Token::StructEnd,
            ],
        );
    }
}