discord-ferris 0.0.2

discord-ferris is a Discord API Rust library under development 🦀
Documentation
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
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
//! Types extracted from https://discord.com/developers/docs/topics/gateway

pub use crate::models::payloads::common::*;
use serde::{Deserialize, Serialize};

use crate::models::payloads::{
    APIApplication, APIApplicationCommandPermission, APIAuditLogEntry, APIAutoModerationAction,
    APIAutoModerationRule, APIBaseGuild, APIBaseGuildMember, APIBaseMessage,
    APIBaseVoiceGuildMember, APIBaseVoiceState, APIChannel, APIEmoji, APIEntitlement,
    APIFlaggedGuildMember, APIGuild, APIGuildIntegration, APIGuildMember, APIGuildMemberAvatar,
    APIGuildMemberJoined, APIGuildMemberUser, APIGuildScheduledEvent, APIInteraction, APIRole,
    APISoundboardSound, APIStageInstance, APISticker, APISubscription, APIThreadChannel,
    APIThreadMember, APIUnavailableGuild, APIUser, APIVoiceState, AutoModerationRuleTriggerType,
    ChannelType, GatewayGuildMembersChunkPresence, GatewayPresenceUpdate, GatewayThreadListSync,
    GatewayThreadMembersUpdate as RawGatewayThreadMembersUpdate, InviteTargetType,
    PresenceUpdateStatus,
};
// use crate::models::rest::ReactionType;

/// Simple replacement for the TS utility `_Nullable<T>`
pub type _Nullable<T> = Option<T>;

pub const GATEWAY_VERSION: &str = "10";

/**
 * @see {@link https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-opcodes}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[repr(u8)]
pub enum GatewayOpcodes {
    /**
     * An event was dispatched
     */
    Dispatch = 0,
    /**
     * A bidirectional opcode to maintain an active gateway connection.
     * Fired periodically by the client, or fired by the gateway to request an immediate heartbeat from the client.
     */
    Heartbeat = 1,
    /**
     * Starts a new session during the initial handshake
     */
    Identify = 2,
    /**
     * Update the client's presence
     */
    PresenceUpdate = 3,
    /**
     * Used to join/leave or move between voice channels
     */
    VoiceStateUpdate = 4,
    /**
     * Resume a previous session that was disconnected
     */
    Resume = 6,
    /**
     * You should attempt to reconnect and resume immediately
     */
    Reconnect = 7,
    /**
     * Request information about offline guild members in a large guild
     */
    RequestGuildMembers = 8,
    /**
     * The session has been invalidated. You should reconnect and identify/resume accordingly
     */
    InvalidSession = 9,
    /**
     * Sent immediately after connecting, contains the `heartbeat_interval` to use
     */
    Hello = 10,
    /**
     * Sent in response to receiving a heartbeat to acknowledge that it has been received
     */
    HeartbeatAck = 11,
    /**
     * Request information about soundboard sounds in a set of guilds
     */
    RequestSoundboardSounds = 31,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-close-event-codes}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[repr(u16)]
pub enum GatewayCloseCodes {
    /**
     * We're not sure what went wrong. Try reconnecting?
     */
    UnknownError = 4000,
    /**
     * You sent an invalid Gateway opcode or an invalid payload for an opcode. Don't do that!
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#payload-structure}
     */
    UnknownOpcode = 4001,
    /**
     * You sent an invalid payload to us. Don't do that!
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway#sending-events}
     */
    DecodeError = 4002,
    /**
     * You sent us a payload prior to identifying
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#identify}
     */
    NotAuthenticated = 4003,
    /**
     * The account token sent with your identify payload is incorrect
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#identify}
     */
    AuthenticationFailed = 4004,
    /**
     * You sent more than one identify payload. Don't do that!
     */
    AlreadyAuthenticated = 4005,
    /**
     * The sequence sent when resuming the session was invalid. Reconnect and start a new session
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#resume}
     */
    InvalidSeq = 4007,
    /**
     * Woah nelly! You're sending payloads to us too quickly. Slow it down! You will be disconnected on receiving this
     */
    RateLimited = 4008,
    /**
     * Your session timed out. Reconnect and start a new one
     */
    SessionTimedOut = 4009,
    /**
     * You sent us an invalid shard when identifying
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway#sharding}
     */
    InvalidShard = 4010,
    /**
     * The session would have handled too many guilds - you are required to shard your connection in order to connect
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway#sharding}
     */
    ShardingRequired = 4011,
    /**
     * You sent an invalid version for the gateway
     */
    InvalidAPIVersion = 4012,
    /**
     * You sent an invalid intent for a Gateway Intent. You may have incorrectly calculated the bitwise value
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway#gateway-intents}
     */
    InvalidIntents = 4013,
    /**
     * You sent a disallowed intent for a Gateway Intent. You may have tried to specify an intent that you have not
     * enabled or are not whitelisted for
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway#gateway-intents}
     * @see {@link https://discord.com/developers/docs/topics/gateway#privileged-intents}
     */
    DisallowedIntents = 4014,
}

use bitflags::bitflags;

bitflags! {
    /**
    * @see {@link https://discord.com/developers/docs/topics/gateway#list-of-intents}
    */
    #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
    #[serde(transparent)]
    pub struct GatewayIntents: u64 {
        const GUILDS                        = 1 << 0;
        const GUILD_MEMBERS                 = 1 << 1;
        const GUILD_MODERATION              = 1 << 2;
        const GUILD_EXPRESSIONS             = 1 << 3;
        const GUILD_INTEGRATIONS            = 1 << 4;
        const GUILD_WEBHOOKS                = 1 << 5;
        const GUILD_INVITES                 = 1 << 6;
        const GUILD_VOICE_STATES            = 1 << 7;
        const GUILD_PRESENCES               = 1 << 8;
        const GUILD_MESSAGES                = 1 << 9;
        const GUILD_MESSAGE_REACTIONS       = 1 << 10;
        const GUILD_MESSAGE_TYPING          = 1 << 11;
        const DIRECT_MESSAGES               = 1 << 12;
        const DIRECT_MESSAGE_REACTIONS      = 1 << 13;
        const DIRECT_MESSAGE_TYPING         = 1 << 14;
        const MESSAGE_CONTENT               = 1 << 15;
        const GUILD_SCHEDULED_EVENTS        = 1 << 16;
        const AUTO_MODERATION_CONFIGURATION = 1 << 20;
        const AUTO_MODERATION_EXECUTION     = 1 << 21;
        const GUILD_MESSAGE_POLLS           = 1 << 24;
        const DIRECT_MESSAGE_POLLS          = 1 << 25;
    }
}

impl GatewayIntents {
    pub const fn minimal() -> Self {
        Self::GUILDS.union(Self::GUILD_MESSAGES)
    }

    pub const fn recommended() -> Self {
        Self::minimal().union(Self::GUILD_MESSAGE_REACTIONS)
    }

    pub const fn privileged() -> Self {
        Self::GUILD_MEMBERS
            .union(Self::GUILD_PRESENCES)
            .union(Self::MESSAGE_CONTENT)
    }

    pub fn non_privileged() -> Self {
        Self::all() - Self::privileged()
    }
}

/// A creation of mine lol
pub type GatewayDispatch<D = serde_json::Value> = _DataPayload<GatewayDispatchEvents, D>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#receive-events}
 */
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum GatewayDispatchEvents {
    ApplicationCommandPermissionsUpdate,
    AutoModerationActionExecution,
    AutoModerationRuleCreate,
    AutoModerationRuleDelete,
    AutoModerationRuleUpdate,
    ChannelCreate,
    ChannelDelete,
    ChannelPinsUpdate,
    ChannelUpdate,
    EntitlementCreate,
    EntitlementDelete,
    EntitlementUpdate,
    GuildAuditLogEntryCreate,
    GuildBanAdd,
    GuildBanRemove,
    GuildCreate,
    GuildDelete,
    GuildEmojisUpdate,
    GuildIntegrationsUpdate,
    GuildMemberAdd,
    GuildMemberRemove,
    GuildMembersChunk,
    GuildMemberUpdate,
    GuildRoleCreate,
    GuildRoleDelete,
    GuildRoleUpdate,
    GuildScheduledEventCreate,
    GuildScheduledEventDelete,
    GuildScheduledEventUpdate,
    GuildScheduledEventUserAdd,
    GuildScheduledEventUserRemove,
    GuildSoundboardSoundCreate,
    GuildSoundboardSoundDelete,
    GuildSoundboardSoundsUpdate,
    GuildSoundboardSoundUpdate,
    SoundboardSounds,
    GuildStickersUpdate,
    GuildUpdate,
    IntegrationCreate,
    IntegrationDelete,
    IntegrationUpdate,
    InteractionCreate,
    InviteCreate,
    InviteDelete,
    MessageCreate,
    MessageDelete,
    MessageDeleteBulk,
    MessagePollVoteAdd,
    MessagePollVoteRemove,
    MessageReactionAdd,
    MessageReactionRemove,
    MessageReactionRemoveAll,
    MessageReactionRemoveEmoji,
    MessageUpdate,
    PresenceUpdate,
    Ready,
    Resumed,
    StageInstanceCreate,
    StageInstanceDelete,
    StageInstanceUpdate,
    SubscriptionCreate,
    SubscriptionDelete,
    SubscriptionUpdate,
    ThreadCreate,
    ThreadDelete,
    ThreadListSync,
    ThreadMembersUpdate,
    ThreadMemberUpdate,
    ThreadUpdate,
    TypingStart,
    UserUpdate,
    VoiceChannelEffectSend,
    VoiceServerUpdate,
    VoiceStateUpdate,
    WebhooksUpdate,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GatewaySendPayload {
    GatewayHeartbeat(GatewayHeartbeat),
    GatewayIdentify(GatewayIdentify),
    GatewayRequestGuildMembers(GatewayRequestGuildMembers),
    GatewayRequestSoundboardSounds(GatewayRequestSoundboardSounds),
    GatewayResume(GatewayResume),
    GatewayUpdatePresence(GatewayUpdatePresence),
    GatewayVoiceStateUpdate(GatewayVoiceStateUpdate),
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GatewayReceivePayload {
    GatewayDispatchPayload(GatewayDispatchPayload),
    GatewayHeartbeatAck(GatewayHeartbeatAck),
    GatewayHeartbeatRequest(GatewayHeartbeatRequest),
    GatewayHello(GatewayHello),
    GatewayInvalidSession(GatewayInvalidSession),
    GatewayReconnect(GatewayReconnect),
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GatewayDispatchPayload {
    GatewayApplicationCommandPermissionsUpdateDispatch(
        GatewayApplicationCommandPermissionsUpdateDispatch,
    ),
    GatewayAutoModerationActionExecutionDispatch(GatewayAutoModerationActionExecutionDispatch),
    GatewayAutoModerationRuleCreateDispatch(GatewayAutoModerationRuleCreateDispatch),
    GatewayAutoModerationRuleDeleteDispatch(GatewayAutoModerationRuleDeleteDispatch),
    GatewayAutoModerationRuleModifyDispatch(GatewayAutoModerationRuleModifyDispatch),
    GatewayChannelModifyDispatch(GatewayChannelModifyDispatch),
    GatewayChannelPinsUpdateDispatch(GatewayChannelPinsUpdateDispatch),
    GatewayEntitlementModifyDispatch(GatewayEntitlementModifyDispatch),
    GatewayGuildAuditLogEntryCreateDispatch(GatewayGuildAuditLogEntryCreateDispatch),
    GatewayGuildBanModifyDispatch(GatewayGuildBanModifyDispatch),
    GatewayGuildCreateDispatch(GatewayGuildCreateDispatch),
    GatewayGuildDeleteDispatch(GatewayGuildDeleteDispatch),
    GatewayGuildEmojisUpdateDispatch(GatewayGuildEmojisUpdateDispatch),
    GatewayGuildIntegrationsUpdateDispatch(GatewayGuildIntegrationsUpdateDispatch),
    GatewayGuildMemberAddDispatch(GatewayGuildMemberAddDispatch),
    GatewayGuildMemberRemoveDispatch(GatewayGuildMemberRemoveDispatch),
    GatewayGuildMembersChunkDispatch(GatewayGuildMembersChunkDispatch),
    GatewayGuildMemberUpdateDispatch(GatewayGuildMemberUpdateDispatch),
    GatewayGuildModifyDispatch(GatewayGuildModifyDispatch),
    GatewayGuildRoleDeleteDispatch(GatewayGuildRoleDeleteDispatch),
    GatewayGuildRoleModifyDispatch(GatewayGuildRoleModifyDispatch),
    GatewayGuildScheduledEventCreateDispatch(GatewayGuildScheduledEventCreateDispatch),
    GatewayGuildScheduledEventDeleteDispatch(GatewayGuildScheduledEventDeleteDispatch),
    GatewayGuildScheduledEventUpdateDispatch(GatewayGuildScheduledEventUpdateDispatch),
    GatewayGuildScheduledEventUserAddDispatch(GatewayGuildScheduledEventUserAddDispatch),
    GatewayGuildScheduledEventUserRemoveDispatch(GatewayGuildScheduledEventUserRemoveDispatch),
    GatewayGuildSoundboardSoundCreateDispatch(GatewayGuildSoundboardSoundCreateDispatch),
    GatewayGuildSoundboardSoundDeleteDispatch(GatewayGuildSoundboardSoundDeleteDispatch),
    GatewayGuildSoundboardSoundsUpdateDispatch(GatewayGuildSoundboardSoundsUpdateDispatch),
    GatewayGuildSoundboardSoundUpdateDispatch(GatewayGuildSoundboardSoundUpdateDispatch),
    GatewayGuildStickersUpdateDispatch(GatewayGuildStickersUpdateDispatch),
    GatewayIntegrationCreateDispatch(GatewayIntegrationCreateDispatch),
    GatewayIntegrationDeleteDispatch(GatewayIntegrationDeleteDispatch),
    GatewayIntegrationUpdateDispatch(GatewayIntegrationUpdateDispatch),
    GatewayInteractionCreateDispatch(GatewayInteractionCreateDispatch),
    GatewayInviteCreateDispatch(GatewayInviteCreateDispatch),
    GatewayInviteDeleteDispatch(GatewayInviteDeleteDispatch),
    GatewayMessageCreateDispatch(GatewayMessageCreateDispatch),
    GatewayMessageDeleteBulkDispatch(GatewayMessageDeleteBulkDispatch),
    GatewayMessageDeleteDispatch(GatewayMessageDeleteDispatch),
    GatewayMessagePollVoteAddDispatch(GatewayMessagePollVoteAddDispatch),
    GatewayMessagePollVoteRemoveDispatch(GatewayMessagePollVoteRemoveDispatch),
    GatewayMessageReactionAddDispatch(GatewayMessageReactionAddDispatch),
    GatewayMessageReactionRemoveAllDispatch(GatewayMessageReactionRemoveAllDispatch),
    GatewayMessageReactionRemoveDispatch(GatewayMessageReactionRemoveDispatch),
    GatewayMessageReactionRemoveEmojiDispatch(GatewayMessageReactionRemoveEmojiDispatch),
    GatewayMessageUpdateDispatch(GatewayMessageUpdateDispatch),
    GatewayPresenceUpdateDispatch(GatewayPresenceUpdateDispatch),
    GatewayReadyDispatch(GatewayReadyDispatch),
    GatewayResumedDispatch(GatewayResumedDispatch),
    GatewaySoundboardSoundsDispatch(GatewaySoundboardSoundsDispatch),
    GatewayStageInstanceCreateDispatch(GatewayStageInstanceCreateDispatch),
    GatewayStageInstanceDeleteDispatch(GatewayStageInstanceDeleteDispatch),
    GatewayStageInstanceUpdateDispatch(GatewayStageInstanceUpdateDispatch),
    GatewaySubscriptionModifyDispatch(GatewaySubscriptionModifyDispatch),
    GatewayThreadCreateDispatch(GatewayThreadCreateDispatch),
    GatewayThreadDeleteDispatch(GatewayThreadDeleteDispatch),
    GatewayThreadListSyncDispatch(GatewayThreadListSyncDispatch),
    GatewayThreadMembersUpdateDispatch(GatewayThreadMembersUpdateDispatch),
    GatewayThreadMemberUpdateDispatch(GatewayThreadMemberUpdateDispatch),
    GatewayThreadUpdateDispatch(GatewayThreadUpdateDispatch),
    GatewayTypingStartDispatch(GatewayTypingStartDispatch),
    GatewayUserUpdateDispatch(GatewayUserUpdateDispatch),
    GatewayVoiceChannelEffectSendDispatch(GatewayVoiceChannelEffectSendDispatch),
    GatewayVoiceServerUpdateDispatch(GatewayVoiceServerUpdateDispatch),
    GatewayVoiceStateUpdateDispatch(GatewayVoiceStateUpdateDispatch),
    GatewayWebhooksUpdateDispatch(GatewayWebhooksUpdateDispatch),
}

// #region Dispatch Payloads

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#hello}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayHello {
    pub op: GatewayOpcodes,
    pub d: GatewayHelloData,
    pub t: Option<serde_json::Value>,
    pub s: Option<serde_json::Value>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#hello}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayHelloData {
    /**
     * The interval (in milliseconds) the client should heartbeat with
     */
    pub heartbeat_interval: i64,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway#sending-heartbeats}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayHeartbeatRequest {
    pub op: GatewayOpcodes,
    pub d: (),
    pub t: Option<serde_json::Value>,
    pub s: Option<serde_json::Value>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#heartbeat}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayHeartbeatAck {
    pub op: GatewayOpcodes,
    pub d: (),
    pub t: Option<serde_json::Value>,
    pub s: Option<serde_json::Value>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#invalid-session}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayInvalidSession {
    pub op: GatewayOpcodes,
    pub d: GatewayInvalidSessionData,
    pub t: Option<serde_json::Value>,
    pub s: Option<serde_json::Value>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#invalid-session}
 */
pub type GatewayInvalidSessionData = bool;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#reconnect}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayReconnect {
    pub op: GatewayOpcodes,
    pub d: (),
    pub t: Option<serde_json::Value>,
    pub s: Option<serde_json::Value>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#ready}
 */
pub type GatewayReadyDispatch = _DataPayload<GatewayDispatchEvents, GatewayReadyDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#ready}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayReadyDispatchData {
    /**
     * Gateway version
     *
     * @see {@link https://discord.com/developers/docs/reference#api-versioning}
     */
    pub v: i64,
    /**
     * Information about the user including email
     *
     * @see {@link https://discord.com/developers/docs/resources/user#user-object}
     */
    pub user: APIUser,
    /**
     * The guilds the user is in
     *
     * @see {@link https://discord.com/developers/docs/resources/guild#unavailable-guild-object}
     */
    pub guilds: Vec<APIUnavailableGuild>,
    /**
     * Used for resuming connections
     */
    pub session_id: String,
    /**
     * Gateway url for resuming connections
     */
    pub resume_gateway_url: String,
    /**
     * The shard information associated with this session, if sent when identifying
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway#sharding}
     */
    pub shard: Option<(i64, i64)>,
    /**
     * Contains `id` and `flags`
     *
     * @see {@link https://discord.com/developers/docs/resources/application#application-object}
     */
    pub application: GatewayReadyApplication,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayReadyApplication {
    pub id: String,
    pub flags: u64,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#resumed}
 */
pub type GatewayResumedDispatch = _DataPayload<GatewayDispatchEvents, ()>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-update}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-delete}
 */
pub type GatewayAutoModerationRuleModifyDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayAutoModerationRuleModifyDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-update}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-delete}
 */
pub type GatewayAutoModerationRuleModifyDispatchData = APIAutoModerationRule;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-create}
 */
pub type GatewayAutoModerationRuleCreateDispatch = GatewayAutoModerationRuleModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-create}
 */
pub type GatewayAutoModerationRuleCreateDispatchData = GatewayAutoModerationRuleModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-update}
 */
pub type GatewayAutoModerationRuleUpdateDispatch = GatewayAutoModerationRuleModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-update}
 */
pub type GatewayAutoModerationRuleUpdateDispatchData = GatewayAutoModerationRuleModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-delete}
 */
pub type GatewayAutoModerationRuleDeleteDispatch = GatewayAutoModerationRuleModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-rule-delete}
 */
pub type GatewayAutoModerationRuleDeleteDispatchData = GatewayAutoModerationRuleModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-action-execution}
 */
pub type GatewayAutoModerationActionExecutionDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayAutoModerationActionExecutionDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#auto-moderation-action-execution}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayAutoModerationActionExecutionDispatchData {
    /**
     * The id of the guild in which action was executed
     */
    pub guild_id: String,
    /**
     * The action which was executed
     */
    pub action: APIAutoModerationAction,
    /**
     * The id of the rule which action belongs to
     */
    pub rule_id: String,
    /**
     * The trigger type of rule which was triggered
     */
    pub rule_trigger_type: AutoModerationRuleTriggerType,
    /**
     * The id of the user which generated the content which triggered the rule
     */
    pub user_id: String,
    /**
     * The id of the channel in which user content was posted
     */
    pub channel_id: Option<String>,
    /**
     * The id of any user message which content belongs to
     *
     * This field will not be present if message was blocked by AutoMod or content was not part of any message
     */
    pub message_id: Option<String>,
    /**
     * The id of any system auto moderation messages posted as a result of this action
     *
     * This field will not be present if this event does not correspond to an action with type {@link AutoModerationActionType.SendAlertMessage}
     */
    pub alert_system_message_id: Option<String>,
    /**
     * The user generated text content
     *
     * `MESSAGE_CONTENT` (`1 << 15`) gateway intent is required to receive non-empty values from this field
     */
    pub content: String,
    /**
     * The word or phrase configured in the rule that triggered the rule
     */
    pub matched_keyword: Option<String>,
    /**
     * The substring in content that triggered the rule
     *
     * `MESSAGE_CONTENT` (`1 << 15`) gateway intent is required to receive non-empty values from this field
     */
    pub matched_content: Option<String>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#application-command-permissions-update}
 */
pub type GatewayApplicationCommandPermissionsUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayApplicationCommandPermissionsUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#application-command-permissions-update}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayApplicationCommandPermissionsUpdateDispatchData {
    /**
     * ID of the command or the application ID
     */
    pub id: String,
    /**
     * ID of the application the command belongs to
     */
    pub application_id: String,
    /**
     * ID of the guild
     */
    pub guild_id: String,
    /**
     * Permissions for the command in the guild, max of 100
     */
    pub permissions: Vec<APIApplicationCommandPermission>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-update}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-delete}
 */
pub type GatewaySubscriptionModifyDispatch =
    _DataPayload<GatewayDispatchEvents, GatewaySubscriptionModifyDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-update}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-delete}
 */
pub type GatewaySubscriptionModifyDispatchData = APISubscription;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-create}
 */
pub type GatewaySubscriptionCreateDispatch = GatewaySubscriptionModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-create}
 */
pub type GatewaySubscriptionCreateDispatchData = GatewaySubscriptionModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-update}
 */
pub type GatewaySubscriptionUpdateDispatch = GatewaySubscriptionModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-update}
 */
pub type GatewaySubscriptionUpdateDispatchData = GatewaySubscriptionModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-delete}
 */
pub type GatewaySubscriptionDeleteDispatch = GatewaySubscriptionModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#subscription-delete}
 */
pub type GatewaySubscriptionDeleteDispatchData = GatewaySubscriptionModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-update}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-delete}
 */
pub type GatewayChannelModifyDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayChannelModifyDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-update}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-delete}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayChannelModifyDispatchData {
    pub guild_id: String,
    #[serde(flatten)]
    pub channel: APIChannel,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-create}
 */
pub type GatewayChannelCreateDispatch = GatewayChannelModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-create}
 */
pub type GatewayChannelCreateDispatchData = GatewayChannelModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-update}
 */
pub type GatewayChannelUpdateDispatch = GatewayChannelModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-update}
 */
pub type GatewayChannelUpdateDispatchData = GatewayChannelModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-delete}
 */
pub type GatewayChannelDeleteDispatch = GatewayChannelModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-delete}
 */
pub type GatewayChannelDeleteDispatchData = GatewayChannelModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-pins-update}
 */
pub type GatewayChannelPinsUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayChannelPinsUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#channel-pins-update}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayChannelPinsUpdateDispatchData {
    /**
     * The id of the guild
     */
    pub guild_id: Option<String>,
    /**
     * The id of the channel
     */
    pub channel_id: String,
    /**
     * The time at which the most recent pinned message was pinned
     */
    pub last_pin_timestamp: Option<String>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-update}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-delete}
 */
pub type GatewayEntitlementModifyDispatchData = APIEntitlement;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-update}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-delete}
 */
pub type GatewayEntitlementModifyDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayEntitlementModifyDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-create}
 */
pub type GatewayEntitlementCreateDispatchData = GatewayEntitlementModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-create}
 */
pub type GatewayEntitlementCreateDispatch = GatewayEntitlementModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-update}
 */
pub type GatewayEntitlementUpdateDispatchData = GatewayEntitlementModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-update}
 */
pub type GatewayEntitlementUpdateDispatch = GatewayEntitlementModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-delete}
 */
pub type GatewayEntitlementDeleteDispatchData = GatewayEntitlementModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#entitlement-delete}
 */
pub type GatewayEntitlementDeleteDispatch = GatewayEntitlementModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-update}
 */
pub type GatewayGuildModifyDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildModifyDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-update}
 */
pub type GatewayGuildModifyDispatchData = APIGuild;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-create}
 */
pub type GatewayGuildCreateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildCreateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-create-guild-create-extra-fields}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayGuildCreateDispatchData {
    /**
     * When this guild was joined at
     *
     * **This field is only sent within the {@link https://discord.com/developers/docs/topics/gateway-events#guild-create | GUILD_CREATE} event**
     */
    pub joined_at: String,
    /**
     * `true` if this is considered a large guild
     *
     * **This field is only sent within the {@link https://discord.com/developers/docs/topics/gateway-events#guild-create | GUILD_CREATE} event**
     */
    pub large: bool,
    /**
     * `true` if this guild is unavailable due to an outage
     */
    pub unavailable: Option<bool>,
    /**
     * Total number of members in this guild
     *
     * **This field is only sent within the {@link https://discord.com/developers/docs/topics/gateway-events#guild-create | GUILD_CREATE} event**
     */
    pub member_count: i64,
    /**
     * States of members currently in voice channels; lacks the `guild_id` key
     *
     * **This field is only sent within the {@link https://discord.com/developers/docs/topics/gateway-events#guild-create | GUILD_CREATE} event**
     *
     * @see {@link https://discord.com/developers/docs/resources/voice#voice-state-object}
     */
    pub voice_states: Vec<APIBaseVoiceState>,
    /**
     * Users in the guild
     *
     * **This field is only sent within the {@link https://discord.com/developers/docs/topics/gateway-events#guild-create | GUILD_CREATE} event**
     *
     * @see {@link https://discord.com/developers/docs/resources/guild#guild-member-object}
     */
    pub members: Vec<APIGuildMember>,
    /**
     * Channels in the guild
     *
     * **This field is only sent within the {@link https://discord.com/developers/docs/topics/gateway-events#guild-create | GUILD_CREATE} event**
     *
     * @see {@link https://discord.com/developers/docs/resources/channel#channel-object}
     */
    pub channels: Vec<APIChannel>,
    /**
     * Threads in the guild
     *
     * **This field is only sent within the {@link https://discord.com/developers/docs/topics/gateway-events#guild-create | GUILD_CREATE} event**
     *
     * @see {@link https://discord.com/developers/docs/resources/channel#channel-object}
     */
    pub threads: Vec<APIChannel>,
    /**
     * Presences of the members in the guild, will only include non-offline members if the size is greater than `large_threshold`
     *
     * **This field is only sent within the {@link https://discord.com/developers/docs/topics/gateway-events#guild-create | GUILD_CREATE} event**
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#presence-update}
     */
    pub presences: Vec<GatewayPresenceUpdate>,
    /**
     * The stage instances in the guild
     *
     * **This field is only sent within the {@link https://discord.com/developers/docs/topics/gateway-events#guild-create | GUILD_CREATE} event**
     *
     * @see {@link https://discord.com/developers/docs/resources/stage-instance#stage-instance-object-stage-instance-structure}
     */
    pub stage_instances: Vec<APIStageInstance>,
    /**
     * The scheduled events in the guild
     *
     * **This field is only sent within the {@link https://discord.com/developers/docs/topics/gateway-events#guild-create | GUILD_CREATE} event**
     *
     * @see {@link https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object}
     */
    pub guild_scheduled_events: Vec<APIGuildScheduledEvent>,
    /**
     * The soundboard sounds in the guild
     *
     * **This field is only sent within the {@link https://discord.com/developers/docs/topics/gateway-events#guild-create | GUILD_CREATE} event**
     *
     * @see {@link https://discord.com/developers/docs/resources/soundboard#soundboard-sound-object}
     */
    pub soundboard_sounds: Vec<APISoundboardSound>,
    #[serde(flatten)]
    pub guild: APIGuild,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-update}
 */
pub type GatewayGuildUpdateDispatch = GatewayGuildModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-update}
 */
pub type GatewayGuildUpdateDispatchData = GatewayGuildModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-delete}
 */
pub type GatewayGuildDeleteDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildDeleteDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-delete}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayGuildDeleteDispatchData {
    /**
     * `true` if this guild is unavailable due to an outage
     *
     * If the field is not set, the user was removed from the guild.
     */
    pub unavailable: Option<bool>,
    #[serde(flatten)]
    pub guild: APIBaseGuild,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-ban-add}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-ban-remove}
 */
pub type GatewayGuildBanModifyDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildBanModifyDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-ban-add}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-ban-remove}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayGuildBanModifyDispatchData {
    /**
     * ID of the guild
     */
    pub guild_id: String,
    /**
     * The banned user
     *
     * @see {@link https://discord.com/developers/docs/resources/user#user-object}
     */
    pub user: APIUser,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-ban-add}
 */
pub type GatewayGuildBanAddDispatch = GatewayGuildBanModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-ban-add}
 */
pub type GatewayGuildBanAddDispatchData = GatewayGuildBanModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-ban-remove}
 */
pub type GatewayGuildBanRemoveDispatch = GatewayGuildBanModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-ban-remove}
 */
pub type GatewayGuildBanRemoveDispatchData = GatewayGuildBanModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-emojis-update}
 */
pub type GatewayGuildEmojisUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildEmojisUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-emojis-update}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayGuildEmojisUpdateDispatchData {
    /**
     * ID of the guild
     */
    pub guild_id: String,
    /**
     * Array of emojis
     *
     * @see {@link https://discord.com/developers/docs/resources/emoji#emoji-object}
     */
    pub emojis: Vec<APIEmoji>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-stickers-update}
 */
pub type GatewayGuildStickersUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildStickersUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-stickers-update}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayGuildStickersUpdateDispatchData {
    /**
     * ID of the guild
     */
    pub guild_id: String,
    /**
     * Array of stickers
     *
     * @see {@link https://discord.com/developers/docs/resources/sticker#sticker-object}
     */
    pub stickers: Vec<APISticker>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-integrations-update}
 */
pub type GatewayGuildIntegrationsUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildIntegrationsUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-integrations-update}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayGuildIntegrationsUpdateDispatchData {
    /**
     * ID of the guild whose integrations were updated
     */
    pub guild_id: String,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-member-add}
 */
pub type GatewayGuildMemberAddDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildMemberAddDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-member-add}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayGuildMemberAddDispatchData {
    /**
     * The id of the guild
     */
    pub guild_id: String,
    #[serde(flatten)]
    pub member: APIGuildMember,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-member-remove}
 */
pub type GatewayGuildMemberRemoveDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildMemberRemoveDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-member-remove}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayGuildMemberRemoveDispatchData {
    /**
     * The id of the guild
     */
    pub guild_id: String,
    /**
     * The user who was removed
     *
     * @see {@link https://discord.com/developers/docs/resources/user#user-object}
     */
    pub user: APIUser,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-member-update}
 */
pub type GatewayGuildMemberUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildMemberUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-member-update}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayGuildMemberUpdateDispatchData {
    /**
     * The id of the guild
     */
    pub guild_id: String,
    #[serde(flatten)]
    pub joined: Option<APIGuildMemberJoined>,
    #[serde(flatten)]
    pub base: APIBaseGuildMember,
    #[serde(flatten)]
    pub voice: Option<APIBaseVoiceGuildMember>,
    #[serde(flatten)]
    pub flagged: Option<APIFlaggedGuildMember>,
    #[serde(flatten)]
    pub avatar: APIGuildMemberAvatar,
    #[serde(flatten)]
    pub user: APIGuildMemberUser,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-members-chunk}
 */
pub type GatewayGuildMembersChunkDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildMembersChunkDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-members-chunk}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayGuildMembersChunkDispatchData {
    /**
     * The id of the guild
     */
    pub guild_id: String,
    /**
     * Set of guild members
     *
     * @see {@link https://discord.com/developers/docs/resources/guild#guild-member-object}
     */
    pub members: Vec<APIGuildMember>,
    /**
     * The chunk index in the expected chunks for this response (`0 <= chunk_index < chunk_count`)
     */
    pub chunk_index: i64,
    /**
     * The total number of expected chunks for this response
     */
    pub chunk_count: i64,
    /**
     * If passing an invalid id to `REQUEST_GUILD_MEMBERS`, it will be returned here
     */
    pub not_found: Option<Vec<serde_json::Value>>,
    /**
     * If passing true to `REQUEST_GUILD_MEMBERS`, presences of the returned members will be here
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#update-presence}
     */
    pub presences: Option<Vec<GatewayGuildMembersChunkPresence>>,
    /**
     * The nonce used in the Guild Members Request
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#request-guild-members}
     */
    pub nonce: Option<String>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-role-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-role-update}
 */
pub type GatewayGuildRoleModifyDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildRoleModifyDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-role-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-role-update}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayGuildRoleModifyDispatchData {
    /**
     * The id of the guild
     */
    pub guild_id: String,
    /**
     * The role created or updated
     *
     * @see {@link https://discord.com/developers/docs/topics/permissions#role-object}
     */
    pub role: APIRole,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-role-create}
 */
pub type GatewayGuildRoleCreateDispatch = GatewayGuildRoleModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-role-create}
 */
pub type GatewayGuildRoleCreateDispatchData = GatewayGuildRoleModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-role-update}
 */
pub type GatewayGuildRoleUpdateDispatch = GatewayGuildRoleModifyDispatch;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-role-update}
 */
pub type GatewayGuildRoleUpdateDispatchData = GatewayGuildRoleModifyDispatchData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-role-delete}
 */
pub type GatewayGuildRoleDeleteDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildRoleDeleteDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-role-delete}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayGuildRoleDeleteDispatchData {
    /**
     * The id of the guild
     */
    pub guild_id: String,
    /**
     * The id of the role
     */
    pub role_id: String,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-create}
 */
pub type GatewayGuildScheduledEventCreateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildScheduledEventCreateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-create}
 */
pub type GatewayGuildScheduledEventCreateDispatchData = APIGuildScheduledEvent;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-update}
 */
pub type GatewayGuildScheduledEventUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildScheduledEventUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-update}
 */
pub type GatewayGuildScheduledEventUpdateDispatchData = APIGuildScheduledEvent;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-delete}
 */
pub type GatewayGuildScheduledEventDeleteDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildScheduledEventDeleteDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-delete}
 */
pub type GatewayGuildScheduledEventDeleteDispatchData = APIGuildScheduledEvent;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-user-add}
 */
pub type GatewayGuildScheduledEventUserAddDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildScheduledEventUserAddDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-user-add}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayGuildScheduledEventUserAddDispatchData {
    pub guild_scheduled_event_id: String,
    pub user_id: String,
    pub guild_id: String,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-user-remove}
 */
pub type GatewayGuildScheduledEventUserRemoveDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildScheduledEventUserAddDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-scheduled-event-user-remove}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayGuildScheduledEventUserRemoveDispatchData {
    pub guild_scheduled_event_id: String,
    pub user_id: String,
    pub guild_id: String,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sound-create}
 */
pub type GatewayGuildSoundboardSoundCreateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildSoundboardSoundCreateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sound-create}
 */
pub type GatewayGuildSoundboardSoundCreateDispatchData = APISoundboardSound;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sound-update}
 */
pub type GatewayGuildSoundboardSoundUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildSoundboardSoundUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sound-update}
 */
pub type GatewayGuildSoundboardSoundUpdateDispatchData = APISoundboardSound;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sound-delete}
 */
pub type GatewayGuildSoundboardSoundDeleteDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildSoundboardSoundDeleteDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sound-delete}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayGuildSoundboardSoundDeleteDispatchData {
    /**
     * The id of the sound that was deleted
     */
    pub sound_id: String,
    /**
     * The id of the guild the sound was in
     */
    pub guild_id: String,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sounds-update}
 */
pub type GatewayGuildSoundboardSoundsUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildSoundboardSoundsUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sounds-update}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayGuildSoundboardSoundsUpdateDispatchData {
    /**
     * The guild's soundboard sounds
     */
    pub soundboard_sounds: Vec<APISoundboardSound>,
    /**
     * The id of the guild
     */
    pub guild_id: String,
}

/**
 * @see {@link https://discord.com/developers/docs/events/gateway-events#soundboard-sounds}
 */
pub type GatewaySoundboardSoundsDispatch =
    _DataPayload<GatewayDispatchEvents, GatewaySoundboardSoundsDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/events/gateway-events#soundboard-sounds}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewaySoundboardSoundsDispatchData {
    /**
     * The guild's soundboard sounds
     */
    pub soundboard_sounds: Vec<APISoundboardSound>,
    /**
     * The id of the guild
     */
    pub guild_id: String,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#integration-create}
 */
pub type GatewayIntegrationCreateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayIntegrationCreateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#integration-create}
 */
pub type GatewayIntegrationCreateDispatchData = APIGuildIntegrationWithGuild;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct APIGuildIntegrationWithGuild {
    pub guild_id: String,
    #[serde(flatten)]
    pub integration: APIGuildIntegration,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#integration-update}
 */
pub type GatewayIntegrationUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayIntegrationUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#integration-update}
 */
pub type GatewayIntegrationUpdateDispatchData = APIGuildIntegrationWithGuild;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#integration-update}
 */
pub type GatewayIntegrationDeleteDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayIntegrationDeleteDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#integration-delete}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayIntegrationDeleteDispatchData {
    /**
     * Integration id
     */
    pub id: String,
    /**
     * ID of the guild
     */
    pub guild_id: String,
    /**
     * ID of the bot/OAuth2 application for this Discord integration
     */
    pub application_id: Option<String>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#interaction-create}
 */
pub type GatewayInteractionCreateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayInteractionCreateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#interaction-create}
 */
pub type GatewayInteractionCreateDispatchData = APIInteraction;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#invite-create}
 */
pub type GatewayInviteCreateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayInviteCreateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#invite-create}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayInviteCreateDispatchData {
    /**
     * The channel the invite is for
     */
    pub channel_id: String,
    /**
     * The unique invite code
     *
     * @see {@link https://discord.com/developers/docs/resources/invite#invite-object}
     */
    pub code: String,
    /**
     * The time at which the invite was created
     */
    pub created_at: i64,
    /**
     * The guild of the invite
     */
    pub guild_id: Option<String>,
    /**
     * The user that created the invite
     *
     * @see {@link https://discord.com/developers/docs/resources/user#user-object}
     */
    pub inviter: Option<APIUser>,
    /**
     * How long the invite is valid for (in seconds)
     */
    pub max_age: i64,
    /**
     * The maximum number of times the invite can be used
     */
    pub max_uses: i64,
    /**
     * The type of target for this voice channel invite
     *
     * @see {@link https://discord.com/developers/docs/resources/invite#invite-object-invite-target-types}
     */
    pub target_type: Option<InviteTargetType>,
    /**
     * The user whose stream to display for this voice channel stream invite
     *
     * @see {@link https://discord.com/developers/docs/resources/user#user-object}
     */
    pub target_user: Option<APIUser>,
    /**
     * The embedded application to open for this voice channel embedded application invite
     */
    pub target_application: Option<APIApplication>,
    /**
     * Whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role)
     */
    pub temporary: bool,
    /**
     * How many times the invite has been used (always will be `0`)
     */
    pub uses: i64,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#invite-delete}
 */
pub type GatewayInviteDeleteDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayInviteDeleteDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#invite-delete}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayInviteDeleteDispatchData {
    /**
     * The channel of the invite
     */
    pub channel_id: String,
    /**
     * The guild of the invite
     */
    pub guild_id: Option<String>,
    /**
     * The unique invite code
     *
     * @see {@link https://discord.com/developers/docs/resources/invite#invite-object}
     */
    pub code: String,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-create}
 */
pub type GatewayMessageCreateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayMessageCreateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-create}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayMessageCreateDispatchData {
    #[serde(flatten)]
    pub extra: GatewayMessageEventExtraFields,
    #[serde(flatten)]
    pub message: APIBaseMessage,
}

impl GatewayMessageCreateDispatchData {
    pub fn is_bot(&self) -> bool {
        self.message.author.bot.unwrap_or(false)
    }
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-update}
 */
pub type GatewayMessageUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayMessageUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-update}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayMessageUpdateDispatchData {
    #[serde(flatten)]
    pub extra: GatewayMessageEventExtraFields,
    #[serde(flatten)]
    pub message: APIBaseMessage,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct APIGuildMemberNoUser {
    #[serde(flatten)]
    pub base: APIBaseGuildMember,
    #[serde(flatten)]
    pub flagged: APIFlaggedGuildMember,
    #[serde(flatten)]
    pub avatar: APIGuildMemberAvatar,
    #[serde(flatten)]
    pub joined: APIGuildMemberJoined,
    #[serde(flatten)]
    pub voice: APIBaseVoiceGuildMember,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct APIUserWithMember {
    /**
     * The `member` field is only present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
     * from text-based guild channels
     *
     * @see {@link https://discord.com/developers/docs/resources/guild#guild-member-object}
     */
    pub member: Option<APIGuildMemberNoUser>,
    #[serde(flatten)]
    pub user: APIUser,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-create-message-create-extra-fields}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayMessageEventExtraFields {
    /**
     * ID of the guild the message was sent in
     */
    pub guild_id: Option<String>,
    /**
     * Member properties for this message's author
     *
     * The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events
     * from text-based guild channels
     *
     * @see {@link https://discord.com/developers/docs/resources/guild#guild-member-object}
     */
    pub member: Option<APIGuildMemberNoUser>,
    /**
     * Users specifically mentioned in the message
     *
     * @see {@link https://discord.com/developers/docs/resources/user#user-object}
     */
    pub mentions: Vec<APIUserWithMember>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-delete}
 */
pub type GatewayMessageDeleteDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayMessageDeleteDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-delete}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayMessageDeleteDispatchData {
    /**
     * The id of the message
     */
    pub id: String,
    /**
     * The id of the channel
     */
    pub channel_id: String,
    /**
     * The id of the guild
     */
    pub guild_id: Option<String>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-delete-bulk}
 */
pub type GatewayMessageDeleteBulkDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayMessageDeleteBulkDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-delete-bulk}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayMessageDeleteBulkDispatchData {
    /**
     * The ids of the messages
     */
    pub ids: Vec<String>,
    /**
     * The id of the channel
     */
    pub channel_id: String,
    /**
     * The id of the guild
     */
    pub guild_id: Option<String>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-reaction-add}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayMessageReactionAddDispatchData {
    /**
     * The member who reacted if this happened in a guild
     *
     * @see {@link https://discord.com/developers/docs/resources/guild#guild-member-object}
     */
    pub member: Option<APIGuildMember>,
    /**
     * The id of the user that posted the message that was reacted to
     */
    pub message_author_id: Option<String>,
    /**
     * Colors used for super-reaction animation in "#rrggbb" format
     */
    pub burst_colors: Option<Vec<String>>,

    /**
     * The id of the user
     */
    pub user_id: String,
    /**
     * The id of the channel
     */
    pub channel_id: String,
    /**
     * The id of the message
     */
    pub message_id: String,
    /**
     * The id of the guild
     */
    pub guild_id: Option<String>,
    /**
     * The emoji used to react
     *
     * @see {@link https://discord.com/developers/docs/resources/emoji#emoji-object}
     */
    pub emoji: APIEmoji,
    /**
     * True if this is a super-reaction
     */
    pub burst: bool,
    /**
     * The type of reaction
     */
    pub r#type: u8,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-reaction-add}
 */
pub type GatewayMessageReactionAddDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayMessageReactionAddDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayMessageReactionRemoveDispatchData {
    /**
     * The id of the user
     */
    pub user_id: String,
    /**
     * The id of the channel
     */
    pub channel_id: String,
    /**
     * The id of the message
     */
    pub message_id: String,
    /**
     * The id of the guild
     */
    pub guild_id: Option<String>,
    /**
     * The emoji used to react
     *
     * @see {@link https://discord.com/developers/docs/resources/emoji#emoji-object}
     */
    pub emoji: APIEmoji,
    /**
     * True if this is a super-reaction
     */
    pub burst: bool,
    /**
     * The type of reaction
     */
    pub r#type: u8,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove}
 */
pub type GatewayMessageReactionRemoveDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayMessageReactionRemoveDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove-all}
 */
pub type GatewayMessageReactionRemoveAllDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayMessageReactionRemoveAllDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove-all}
 */
pub type GatewayMessageReactionRemoveAllDispatchData = GatewayMessageReactionRemoveData;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove-emoji}
 */
pub type GatewayMessageReactionRemoveEmojiDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayMessageReactionRemoveEmojiDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove-emoji}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayMessageReactionRemoveEmojiDispatchData {
    /**
     * The emoji that was removed
     */
    pub emoji: APIEmoji,
    /**
     * The id of the channel
     */
    pub channel_id: String,
    /**
     * The id of the message
     */
    pub message_id: String,
    /**
     * The id of the guild
     */
    pub guild_id: Option<String>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#presence-update}
 */
pub type GatewayPresenceUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayPresenceUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#presence-update}
 */
pub type GatewayPresenceUpdateDispatchData = GatewayPresenceUpdate;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#stage-instance-create}
 */
pub type GatewayStageInstanceCreateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayStageInstanceCreateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#stage-instance-create}
 */
pub type GatewayStageInstanceCreateDispatchData = APIStageInstance;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#stage-instance-delete}
 */
pub type GatewayStageInstanceDeleteDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayStageInstanceDeleteDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#stage-instance-delete}
 */
pub type GatewayStageInstanceDeleteDispatchData = APIStageInstance;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#stage-instance-update}
 */
pub type GatewayStageInstanceUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayStageInstanceUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#stage-instance-update}
 */
pub type GatewayStageInstanceUpdateDispatchData = APIStageInstance;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-list-sync}
 */
pub type GatewayThreadListSyncDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayThreadListSyncDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-list-sync}
 */
pub type GatewayThreadListSyncDispatchData = GatewayThreadListSync;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-members-update}
 */
pub type GatewayThreadMembersUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayThreadMembersUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-members-update}
 */
pub type GatewayThreadMembersUpdateDispatchData = RawGatewayThreadMembersUpdate;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-member-update}
 */
pub type GatewayThreadMemberUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayThreadMemberUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-member-update}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayThreadMemberUpdateDispatchData {
    pub guild_id: String,
    #[serde(flatten)]
    pub member: APIThreadMember,
}

/**
 * @deprecated This type doesn't accurately reflect the Discord API.
 * Use {@link GatewayThreadCreateDispatch},
 * {@link GatewayThreadUpdateDispatch}, or
 * {@link GatewayThreadDeleteDispatch} instead.
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-create}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-update}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-delete}
 */
pub type GatewayThreadModifyDispatch = _DataPayload<GatewayDispatchEvents, APIThreadChannel>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-create}
 */
pub type GatewayThreadCreateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayThreadCreateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-create}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayThreadCreateDispatchData {
    /**
     * Whether the thread is newly created or not.
     */
    pub newly_created: Option<bool>,
    #[serde(flatten)]
    pub thread: APIThreadChannel,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-update}
 */
pub type GatewayThreadUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayThreadUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-update}
 */
pub type GatewayThreadUpdateDispatchData = APIThreadChannel;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-delete}
 */
pub type GatewayThreadDeleteDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayThreadDeleteDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#thread-delete}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayThreadDeleteDispatchData {
    /**
     * The id of the channel
     */
    pub id: String,
    /**
     * The id of the guild
     */
    pub guild_id: String,
    /**
     * The id of the parent channel of the thread
     */
    pub parent_id: String,
    /**
     * The type of the channel
     *
     * @see {@link https://discord.com/developers/docs/resources/channel#channel-object-channel-types}
     */
    pub r#type: ChannelType,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#typing-start}
 */
pub type GatewayTypingStartDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayTypingStartDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#typing-start}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayTypingStartDispatchData {
    /**
     * The id of the channel
     */
    pub channel_id: String,
    /**
     * The id of the guild
     */
    pub guild_id: Option<String>,
    /**
     * The id of the user
     */
    pub user_id: String,
    /**
     * Unix time (in seconds) of when the user started typing
     */
    pub timestamp: i64,
    /**
     * The member who started typing if this happened in a guild
     *
     * @see {@link https://discord.com/developers/docs/resources/guild#guild-member-object}
     */
    pub member: Option<APIGuildMember>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#user-update}
 */
pub type GatewayUserUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayUserUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#user-update}
 */
pub type GatewayUserUpdateDispatchData = APIUser;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#voice-channel-effect-send}
 */
pub type GatewayVoiceChannelEffectSendDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayVoiceChannelEffectSendDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#voice-channel-effect-send}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayVoiceChannelEffectSendDispatchData {
    /**
     * ID of the channel the effect was sent in
     */
    pub channel_id: String,
    /**
     * ID of the guild the effect was sent in
     */
    pub guild_id: String,
    /**
     * ID of the user who sent the effect
     */
    pub user_id: String,
    /**
     * The emoji sent, for emoji reaction and soundboard effects
     */
    pub emoji: Option<APIEmoji>,
    /**
     * The type of emoji animation, for emoji reaction and soundboard effects
     */
    pub animation_type: Option<VoiceChannelEffectSendAnimationType>,
    /**
     * The ID of the emoji animation, for emoji reaction and soundboard effects
     */
    pub animation_id: Option<i64>,
    /**
     * The ID of the soundboard sound, for soundboard effects
     */
    pub sound_id: Option<StringOrNumber>,
    /**
     * The volume of the soundboard sound, from 0 to 1, for soundboard effects
     */
    pub sound_volume: Option<f64>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#voice-channel-effect-send-animation-types}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum VoiceChannelEffectSendAnimationType {
    /**
     * A fun animation, sent by a Nitro subscriber
     */
    Premium,
    /**
     * The standard animation
     */
    Basic,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum StringOrNumber {
    String(String),
    Number(i64),
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#voice-state-update}
 */
pub type GatewayVoiceStateUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayVoiceStateUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#voice-state-update}
 */
pub type GatewayVoiceStateUpdateDispatchData = APIVoiceState;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#voice-server-update}
 */
pub type GatewayVoiceServerUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayVoiceServerUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#voice-server-update}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayVoiceServerUpdateDispatchData {
    /**
     * Voice connection token
     */
    pub token: String,
    /**
     * The guild this voice server update is for
     */
    pub guild_id: String,
    /**
     * The voice server host
     *
     * A `null` endpoint means that the voice server allocated has gone away and is trying to be reallocated.
     * You should attempt to disconnect from the currently connected voice server, and not attempt to reconnect
     * until a new voice server is allocated
     */
    pub endpoint: Option<String>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#webhooks-update}
 */
pub type GatewayWebhooksUpdateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayWebhooksUpdateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#webhooks-update}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayWebhooksUpdateDispatchData {
    /**
     * The id of the guild
     */
    pub guild_id: String,
    /**
     * The id of the channel
     */
    pub channel_id: String,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-audit-log-entry-create}
 */
pub type GatewayGuildAuditLogEntryCreateDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayGuildAuditLogEntryCreateDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-audit-log-entry-create}
 */
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct GatewayGuildAuditLogEntryCreateDispatchData {
    /**
     * ID of the guild
     */
    pub guild_id: String,
    #[serde(flatten)]
    pub entry: APIAuditLogEntry,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-add}
 */
pub type GatewayMessagePollVoteAddDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayMessagePollVoteDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-remove}
 */
pub type GatewayMessagePollVoteRemoveDispatch =
    _DataPayload<GatewayDispatchEvents, GatewayMessagePollVoteDispatchData>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-add}
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-remove}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayMessagePollVoteDispatchData {
    /**
     * ID of the user
     */
    pub user_id: String,
    /**
     * ID of the channel
     */
    pub channel_id: String,
    /**
     * ID of the message
     */
    pub message_id: String,
    /**
     * ID of the guild
     */
    pub guild_id: Option<String>,
    /**
     * ID of the answer
     */
    pub answer_id: i64,
}

// #endregion Dispatch Payloads

// #region Sendable Payloads

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway#sending-heartbeats}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayHeartbeat {
    pub op: GatewayOpcodes,
    pub d: GatewayHeartbeatData,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway#sending-heartbeats}
 */
pub type GatewayHeartbeatData = Option<i64>;

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#identify}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayIdentify {
    pub op: GatewayOpcodes,
    pub d: GatewayIdentifyData,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#identify}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayIdentifyData {
    /**
     * Authentication token
     */
    pub token: String,
    /**
     * Connection properties
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#identify-identify-connection-properties}
     */
    pub properties: GatewayIdentifyProperties,
    /**
     * Whether this connection supports compression of packets
     *
     * @defaultValue `false`
     */
    pub compress: Option<bool>,
    /**
     * Value between 50 and 250, total number of members where the gateway will stop sending
     * offline members in the guild member list
     *
     * @defaultValue `50`
     */
    pub large_threshold: Option<i64>,
    /**
     * Used for Guild Sharding
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway#sharding}
     */
    pub shard: Option<(i64, i64)>,
    /**
     * Presence structure for initial presence information
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#update-presence}
     */
    pub presence: Option<GatewayPresenceUpdateData>,
    /**
     * The Gateway Intents you wish to receive
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway#gateway-intents}
     */
    pub intents: i64,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#identify-identify-connection-properties}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayIdentifyProperties {
    /**
     * Your operating system
     */
    pub os: String,
    /**
     * Your library name
     */
    pub browser: String,
    /**
     * Your library name
     */
    pub device: String,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#resume}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayResume {
    pub op: GatewayOpcodes,
    pub d: GatewayResumeData,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#resume}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayResumeData {
    /**
     * Session token
     */
    pub token: String,
    /**
     * Session id
     */
    pub session_id: String,
    /**
     * Last sequence number received
     */
    pub seq: i64,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#request-guild-members}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayRequestGuildMembers {
    pub op: GatewayOpcodes,
    pub d: GatewayRequestGuildMembersData,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#request-guild-members}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayRequestGuildMembersDataBase {
    /**
     * ID of the guild to get members for
     */
    pub guild_id: String,
    /**
     * Used to specify if we want the presences of the matched members
     */
    pub presences: Option<bool>,
    /**
     * Nonce to identify the Guild Members Chunk response
     *
     * Nonce can only be up to 32 bytes. If you send an invalid nonce it will be ignored and the reply member_chunk(s) will not have a `nonce` set.
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#guild-members-chunk}
     */
    pub nonce: Option<String>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#request-guild-members}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayRequestGuildMembersDataWithUserIds {
    #[serde(flatten)]
    pub base: GatewayRequestGuildMembersDataBase,
    /**
     * Used to specify which users you wish to fetch
     */
    pub user_ids: StringOrStrings,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum StringOrStrings {
    One(String),
    Many(Vec<String>),
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#request-guild-members}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayRequestGuildMembersDataWithQuery {
    #[serde(flatten)]
    pub base: GatewayRequestGuildMembersDataBase,
    /**
     * String that username starts with, or an empty string to return all members
     */
    pub query: String,
    /**
     * Maximum number of members to send matching the `query`;
     * a limit of `0` can be used with an empty string `query` to return all members
     */
    pub limit: i64,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#request-guild-members}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GatewayRequestGuildMembersData {
    WithQuery(GatewayRequestGuildMembersDataWithQuery),
    WithUserIds(GatewayRequestGuildMembersDataWithUserIds),
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#request-soundboard-sounds}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayRequestSoundboardSounds {
    pub op: GatewayOpcodes,
    pub d: GatewayRequestSoundboardSoundsData,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#request-soundboard-sounds}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayRequestSoundboardSoundsData {
    /**
     * The ids of the guilds to get soundboard sounds for
     */
    pub guild_ids: Vec<String>,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#update-voice-state}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayVoiceStateUpdate {
    pub op: GatewayOpcodes,
    pub d: GatewayVoiceStateUpdateData,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#update-voice-state}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayVoiceStateUpdateData {
    /**
     * ID of the guild
     */
    pub guild_id: String,
    /**
     * ID of the voice channel client wants to join (`null` if disconnecting)
     */
    pub channel_id: Option<String>,
    /**
     * Is the client muted
     */
    pub self_mute: bool,
    /**
     * Is the client deafened
     */
    pub self_deaf: bool,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#update-presence}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayUpdatePresence {
    pub op: GatewayOpcodes,
    pub d: GatewayPresenceUpdateData,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#update-presence-gateway-presence-update-structure}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayPresenceUpdateData {
    /**
     * Unix time (in milliseconds) of when the client went idle, or `null` if the client is not idle
     */
    pub since: Option<i64>,
    /**
     * The user's activities
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#activity-object}
     */
    pub activities: Vec<GatewayActivityUpdateData>,
    /**
     * The user's new status
     *
     * @see {@link https://discord.com/developers/docs/topics/gateway-events#update-presence-status-types}
     */
    pub status: PresenceUpdateStatus,
    /**
     * Whether or not the client is afk
     */
    pub afk: bool,
}

/**
 * @see {@link https://discord.com/developers/docs/topics/gateway-events#activity-object-activity-structure}
 */
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayActivityUpdateData {
    pub name: Option<String>,
    pub state: Option<String>,
    #[serde(rename = "type")]
    pub r#type: Option<i64>,
    pub url: Option<String>,
}

// #endregion Sendable Payloads

// #region Shared
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct _BaseBasePayload {
    /**
     * Opcode for the payload
     */
    pub op: GatewayOpcodes,
    /**
     * Event data
     */
    pub d: Option<serde_json::Value>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct _BasePayload {
    /**
     * Sequence number, used for resuming sessions and heartbeats
     */
    pub s: i64,
    /**
     * The event name for this payload
     */
    pub t: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct _NonDispatchPayload {
    pub t: Option<serde_json::Value>,
    pub s: Option<serde_json::Value>,
    #[serde(flatten)]
    pub base: _BaseBasePayload,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct _DataPayload<Event, D> {
    pub op: GatewayOpcodes,
    pub t: Event,
    pub d: D,
    pub s: i64,
}

/**
 * This is not used internally anymore, just remains to be non-breaking
 */
pub type GatewayMessageReactionData<E> = _DataPayload<E, GatewayMessageReactionAddDispatchData>;

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GatewayMessageReactionRemoveData {
    /**
     * The id of the channel
     */
    pub channel_id: String,
    /**
     * The id of the message
     */
    pub message_id: String,
    /**
     * The id of the guild
     */
    pub guild_id: Option<String>,
}
// #endregion Shared