frakti 0.1.0

Telegram bot API client for Rust, with a focus on single-threaded async runtime support
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
//! [Available Types](https://core.telegram.org/bots/api#available-types) of the Bot API.

use serde::{Deserialize, Serialize};

use super::{
    games::{CallbackGame, Game},
    gifts::{AcceptedGiftTypes, GiftInfo, UniqueGiftColors, UniqueGiftInfo},
    macros::{apistruct, apply},
    parse_mode::ParseMode,
    passport::PassportData,
    payments::{Invoice, RefundedPayment, StarAmount, SuccessfulPayment},
    stickers::Sticker,
};

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

impl From<i64> for ChatId {
    fn from(id: i64) -> Self {
        Self::Integer(id)
    }
}

impl From<String> for ChatId {
    fn from(id: String) -> Self {
        Self::String(id)
    }
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum ReplyMarkup {
    InlineKeyboardMarkup(InlineKeyboardMarkup),
    ReplyKeyboardMarkup(ReplyKeyboardMarkup),
    ReplyKeyboardRemove(ReplyKeyboardRemove),
    ForceReply(ForceReply),
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ChatAction {
    Typing,
    UploadPhoto,
    RecordVideo,
    UploadVideo,
    RecordVoice,
    UploadVoice,
    UploadDocument,
    ChooseSticker,
    FindLocation,
    RecordVideoNote,
    UploadVideoNote,
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ButtonStyle {
    Danger,
    Success,
    Primary,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum BotCommandScope {
    Default,
    AllPrivateChats,
    AllGroupChats,
    AllChatAdministrators,
    Chat(BotCommandScopeChat),
    ChatAdministrators(BotCommandScopeChatAdministrators),
    ChatMember(BotCommandScopeChatMember),
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BotCommandScopeChat {
    pub chat_id: ChatId,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BotCommandScopeChatAdministrators {
    pub chat_id: ChatId,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BotCommandScopeChatMember {
    pub chat_id: ChatId,
    pub user_id: u64,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ReplyParameters {
    pub message_id: i32,
    pub chat_id: Option<ChatId>,
    pub allow_sending_without_reply: Option<bool>,
    pub quote: Option<String>,
    pub quote_parse_mode: Option<ParseMode>,
    pub quote_entities: Option<Vec<MessageEntity>>,
    pub quote_position: Option<u32>,
    pub checklist_task_id: Option<i64>,
    pub poll_option_id: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum ChatMember {
    Creator(ChatMemberOwner),
    Administrator(ChatMemberAdministrator),
    Member(ChatMemberMember),
    Restricted(ChatMemberRestricted),
    Left(ChatMemberLeft),
    Kicked(ChatMemberBanned),
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ChatType {
    Private,
    Group,
    Supergroup,
    Channel,
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum MessageEntityType {
    Mention,
    Hashtag,
    Cashtag,
    BotCommand,
    Url,
    Email,
    PhoneNumber,
    Bold,
    Italic,
    Underline,
    Strikethrough,
    Spoiler,
    Code,
    Pre,
    TextLink,
    TextMention,
    CustomEmoji,
    DateTime,
    Blockquote,
    ExpandableBlockquote,
    #[serde(other)]
    Unknown,
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum PollType {
    Regular,
    Quiz,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum MenuButton {
    Commands,
    WebApp(MenuButtonWebApp),
    Default,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ChatBackground {
    Fill(BackgroundTypeFill),
    Wallpaper(BackgroundTypeWallpaper),
    Pattern(BackgroundTypePattern),
    ChatTheme(BackgroundTypeChatTheme),
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum BackgroundFill {
    Solid(BackgroundFillSolid),
    Gradient(BackgroundFillGradient),
    FreeformGradient(BackgroundFillFreeformGradient),
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct MenuButtonWebApp {
    pub text: String,
    pub web_app: WebAppInfo,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatMemberOwner {
    pub user: User,
    pub custom_title: Option<String>,
    pub is_anonymous: bool,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatMemberAdministrator {
    pub user: User,
    pub can_be_edited: bool,
    pub is_anonymous: bool,
    pub can_manage_chat: bool,
    pub can_delete_messages: bool,
    pub can_manage_video_chats: bool,
    pub can_restrict_members: bool,
    pub can_promote_members: bool,
    pub can_change_info: bool,
    pub can_invite_users: bool,
    pub can_post_messages: Option<bool>,
    pub can_edit_messages: Option<bool>,
    pub can_pin_messages: Option<bool>,
    pub can_post_stories: Option<bool>,
    pub can_edit_stories: Option<bool>,
    pub can_delete_stories: Option<bool>,
    pub can_manage_topics: Option<bool>,
    pub can_manage_direct_messages: Option<bool>,
    pub can_manage_tags: Option<bool>,
    pub custom_title: Option<String>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatMemberMember {
    pub tag: Option<String>,
    pub user: User,
    pub until_date: Option<u64>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatMemberRestricted {
    pub tag: Option<String>,
    pub user: User,
    pub is_member: bool,
    pub can_send_messages: bool,
    pub can_send_audios: bool,
    pub can_send_documents: bool,
    pub can_send_photos: bool,
    pub can_send_videos: bool,
    pub can_send_video_notes: bool,
    pub can_send_voice_notes: bool,
    pub can_send_polls: bool,
    pub can_send_other_messages: bool,
    pub can_add_web_page_previews: bool,
    pub can_edit_tag: bool,
    pub can_change_info: bool,
    pub can_invite_users: bool,
    pub can_pin_messages: bool,
    pub can_manage_topics: bool,
    pub until_date: u64,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatMemberLeft {
    pub user: User,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatMemberBanned {
    pub user: User,
    pub until_date: u64,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct VideoChatStarted {}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct VideoChatScheduled {
    pub start_date: u64,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BotDescription {
    pub description: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BotName {
    pub name: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BotShortDescription {
    pub short_description: String,
}

/// Control which updates to receive.
/// Specify an empty list to receive all update types except `ChatMember`.
/// [Official documentation](https://core.telegram.org/bots/api#getupdates).
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum AllowedUpdate {
    Message,
    EditedMessage,
    ChannelPost,
    EditedChannelPost,
    BusinessConnection,
    BusinessMessage,
    EditedBusinessMessage,
    DeletedBusinessMessages,
    MessageReaction,
    MessageReactionCount,
    InlineQuery,
    ChosenInlineResult,
    CallbackQuery,
    ShippingQuery,
    PreCheckoutQuery,
    PurchasedPaidMedia,
    Poll,
    PollAnswer,
    MyChatMember,
    ChatMember,
    ChatJoinRequest,
    ChatBoost,
    RemovedChatBoost,
    ManagedBot,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct User {
    pub id: u64,
    pub is_bot: bool,
    pub first_name: String,
    pub last_name: Option<String>,
    pub username: Option<String>,
    pub language_code: Option<String>,
    pub is_premium: Option<bool>,
    pub added_to_attachment_menu: Option<bool>,
    pub can_join_groups: Option<bool>,
    pub can_read_all_group_messages: Option<bool>,
    pub supports_inline_queries: Option<bool>,
    pub can_connect_to_business: Option<bool>,
    pub has_main_web_app: Option<bool>,
    pub has_topics_enabled: Option<bool>,
    pub allows_users_to_create_topics: Option<bool>,
    pub can_manage_bots: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Chat {
    pub id: i64,
    #[serde(rename = "type")]
    pub type_field: ChatType,
    pub title: Option<String>,
    pub username: Option<String>,
    pub first_name: Option<String>,
    pub last_name: Option<String>,
    pub is_forum: Option<bool>,
    pub is_direct_messages: Option<bool>,
}

#[apply(apistruct!)]
pub struct ChatFullInfo {
    pub id: i64,
    #[serde(rename = "type")]
    pub type_field: ChatType,
    pub title: Option<String>,
    pub username: Option<String>,
    pub first_name: Option<String>,
    pub last_name: Option<String>,
    pub is_forum: Option<bool>,
    pub is_direct_messages: Option<bool>,
    pub photo: Option<ChatPhoto>,
    pub active_usernames: Option<Vec<String>>,
    pub birthdate: Option<Birthdate>,
    pub business_intro: Option<BusinessIntro>,
    pub business_location: Option<BusinessLocation>,
    pub business_opening_hours: Option<BusinessOpeningHours>,
    pub personal_chat: Option<Box<Chat>>,
    pub parent_chat: Option<Box<Chat>>,
    pub available_reactions: Option<Vec<ReactionType>>,
    pub accent_color_id: Option<u16>,
    pub max_reaction_count: Option<u16>,
    pub background_custom_emoji_id: Option<String>,
    pub profile_accent_color_id: Option<u16>,
    pub profile_background_custom_emoji_id: Option<String>,
    pub emoji_status_custom_emoji_id: Option<String>,
    pub emoji_status_expiration_date: Option<u32>,
    pub bio: Option<String>,
    pub has_private_forwards: Option<bool>,
    pub has_restricted_voice_and_video_messages: Option<bool>,
    pub join_to_send_messages: Option<bool>,
    pub join_by_request: Option<bool>,
    pub description: Option<String>,
    pub invite_link: Option<String>,
    pub pinned_message: Option<Box<Message>>,
    pub permissions: Option<ChatPermissions>,
    pub accepted_gift_types: AcceptedGiftTypes,
    pub can_send_paid_media: Option<bool>,
    pub slow_mode_delay: Option<u16>,
    pub unrestrict_boost_count: Option<u32>,
    pub message_auto_delete_time: Option<u32>,
    pub has_aggressive_anti_spam_enabled: Option<bool>,
    pub has_hidden_members: Option<bool>,
    pub has_protected_content: Option<bool>,
    pub has_visible_history: Option<bool>,
    pub sticker_set_name: Option<String>,
    pub can_set_sticker_set: Option<bool>,
    pub custom_emoji_sticker_set_name: Option<String>,
    pub linked_chat_id: Option<i64>,
    pub location: Option<ChatLocation>,
    pub rating: Option<UserRating>,
    pub first_profile_audio: Option<Audio>,
    pub unique_gift_colors: Option<UniqueGiftColors>,
    pub paid_message_star_count: Option<u32>,
}

#[apply(apistruct!)]
pub struct Message {
    pub message_id: i32,
    pub message_thread_id: Option<i32>,
    pub direct_messages_topic: Option<Box<DirectMessagesTopic>>,
    pub from: Option<Box<User>>,
    pub sender_chat: Option<Box<Chat>>,
    pub sender_boost_count: Option<u32>,
    pub sender_business_bot: Option<Box<User>>,
    pub sender_tag: Option<String>,
    pub date: u64,
    pub business_connection_id: Option<String>,
    pub chat: Box<Chat>,
    pub forward_origin: Option<Box<MessageOrigin>>,
    pub is_topic_message: Option<bool>,
    pub is_automatic_forward: Option<bool>,
    pub reply_to_message: Option<Box<Self>>,
    pub external_reply: Option<Box<ExternalReplyInfo>>,
    pub quote: Option<Box<TextQuote>>,
    pub reply_to_story: Option<Box<Story>>,
    pub reply_to_checklist_task_id: Option<i64>,
    pub reply_to_poll_option_id: Option<String>,
    pub via_bot: Option<Box<User>>,
    pub edit_date: Option<u64>,
    pub has_protected_content: Option<bool>,
    pub is_from_offline: Option<bool>,
    pub is_paid_post: Option<bool>,
    pub media_group_id: Option<String>,
    pub author_signature: Option<String>,
    pub text: Option<String>,
    pub entities: Option<Vec<MessageEntity>>,
    pub link_preview_options: Option<LinkPreviewOptions>,
    pub suggested_post_info: Option<SuggestedPostInfo>,
    pub effect_id: Option<String>,
    pub animation: Option<Box<Animation>>,
    pub audio: Option<Box<Audio>>,
    pub document: Option<Box<Document>>,
    pub paid_media: Option<Box<PaidMediaInfo>>,
    pub photo: Option<Vec<PhotoSize>>,
    pub sticker: Option<Box<Sticker>>,
    pub story: Option<Box<Story>>,
    pub video: Option<Box<Video>>,
    pub video_note: Option<Box<VideoNote>>,
    pub voice: Option<Box<Voice>>,
    pub caption: Option<String>,
    pub caption_entities: Option<Vec<MessageEntity>>,
    pub show_caption_above_media: Option<bool>,
    pub has_media_spoiler: Option<bool>,
    pub checklist: Option<Checklist>,
    pub contact: Option<Box<Contact>>,
    pub dice: Option<Box<Dice>>,
    pub game: Option<Box<Game>>,
    pub poll: Option<Box<Poll>>,
    pub venue: Option<Box<Venue>>,
    pub location: Option<Box<Location>>,
    pub new_chat_members: Option<Vec<User>>,
    pub left_chat_member: Option<Box<User>>,
    pub chat_owner_left: Option<Box<ChatOwnerLeft>>,
    pub chat_owner_changed: Option<Box<ChatOwnerChanged>>,
    pub new_chat_title: Option<String>,
    pub new_chat_photo: Option<Vec<PhotoSize>>,
    pub delete_chat_photo: Option<bool>,
    pub group_chat_created: Option<bool>,
    pub supergroup_chat_created: Option<bool>,
    pub channel_chat_created: Option<bool>,
    pub message_auto_delete_timer_changed: Option<Box<MessageAutoDeleteTimerChanged>>,
    pub migrate_to_chat_id: Option<i64>,
    pub migrate_from_chat_id: Option<i64>,
    pub pinned_message: Option<Box<MaybeInaccessibleMessage>>,
    pub invoice: Option<Box<Invoice>>,
    pub successful_payment: Option<Box<SuccessfulPayment>>,
    pub refunded_payment: Option<Box<RefundedPayment>>,
    pub users_shared: Option<Box<UsersShared>>,
    pub chat_shared: Option<Box<ChatShared>>,
    pub gift: Option<GiftInfo>,
    pub unique_gift: Option<UniqueGiftInfo>,
    pub gift_upgrade_sent: Option<GiftInfo>,
    pub connected_website: Option<String>,
    pub write_access_allowed: Option<WriteAccessAllowed>,
    pub passport_data: Option<Box<PassportData>>,
    pub proximity_alert_triggered: Option<Box<ProximityAlertTriggered>>,
    pub boost_added: Option<Box<ChatBoostAdded>>,
    pub chat_background_set: Option<Box<ChatBackground>>,
    pub checklist_tasks_done: Option<Box<ChecklistTasksDone>>,
    pub checklist_tasks_added: Option<Box<ChecklistTasksAdded>>,
    pub direct_message_price_changed: Option<Box<DirectMessagePriceChanged>>,
    pub forum_topic_created: Option<Box<ForumTopicCreated>>,
    pub forum_topic_edited: Option<Box<ForumTopicEdited>>,
    pub forum_topic_closed: Option<Box<ForumTopicClosed>>,
    pub forum_topic_reopened: Option<Box<ForumTopicReopened>>,
    pub general_forum_topic_hidden: Option<Box<GeneralForumTopicHidden>>,
    pub general_forum_topic_unhidden: Option<Box<GeneralForumTopicUnhidden>>,
    pub giveaway_created: Option<GiveawayCreated>,
    pub giveaway: Option<Giveaway>,
    pub giveaway_winners: Option<GiveawayWinners>,
    pub giveaway_completed: Option<GiveawayCompleted>,
    pub managed_bot_created: Option<Box<ManagedBotCreated>>,
    pub paid_message_price_changed: Option<PaidMessagePriceChanged>,
    pub suggested_post_approved: Option<Box<SuggestedPostApproved>>,
    pub suggested_post_approval_failed: Option<Box<SuggestedPostApprovalFailed>>,
    pub suggested_post_declined: Option<Box<SuggestedPostDeclined>>,
    pub poll_option_added: Option<Box<PollOptionAdded>>,
    pub poll_option_deleted: Option<Box<PollOptionDeleted>>,
    pub suggested_post_paid: Option<Box<SuggestedPostPaid>>,
    pub suggested_post_refunded: Option<Box<SuggestedPostRefunded>>,
    pub video_chat_scheduled: Option<Box<VideoChatScheduled>>,
    pub video_chat_started: Option<Box<VideoChatStarted>>,
    pub video_chat_ended: Option<Box<VideoChatEnded>>,
    pub video_chat_participants_invited: Option<Box<VideoChatParticipantsInvited>>,
    pub web_app_data: Option<Box<WebAppData>>,
    pub reply_markup: Option<Box<InlineKeyboardMarkup>>,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct MessageId {
    pub message_id: i32,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct MessageEntity {
    #[serde(rename = "type")]
    pub type_field: MessageEntityType,
    pub offset: u16,
    pub length: u16,
    pub url: Option<String>,
    pub user: Option<User>,
    pub language: Option<String>,
    pub custom_emoji_id: Option<String>,
    pub unix_time: Option<u64>,
    pub date_time_format: Option<String>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct TextQuote {
    pub text: String,
    pub entities: Option<Vec<MessageEntity>>,
    pub position: u32,
    pub is_manual: Option<bool>,
}

#[apply(apistruct!)]
pub struct ExternalReplyInfo {
    pub origin: MessageOrigin,
    pub chat: Option<Box<Chat>>,
    pub message_id: Option<i32>,
    pub link_preview_options: Option<LinkPreviewOptions>,
    pub animation: Option<Animation>,
    pub audio: Option<Audio>,
    pub document: Option<Document>,
    pub paid_media: Option<PaidMediaInfo>,
    pub photo: Option<Vec<PhotoSize>>,
    pub sticker: Option<Sticker>,
    pub story: Option<Story>,
    pub video: Option<Video>,
    pub video_note: Option<VideoNote>,
    pub voice: Option<Voice>,
    pub has_media_spoiler: Option<bool>,
    pub checklist: Option<Checklist>,
    pub contact: Option<Contact>,
    pub dice: Option<Dice>,
    pub game: Option<Game>,
    pub giveaway: Option<Giveaway>,
    pub giveaway_winners: Option<GiveawayWinners>,
    pub invoice: Option<Invoice>,
    pub location: Option<Location>,
    pub poll: Option<Poll>,
    pub venue: Option<Venue>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum MessageOrigin {
    User(MessageOriginUser),
    HiddenUser(MessageOriginHiddenUser),
    Chat(MessageOriginChat),
    Channel(MessageOriginChannel),
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct MessageOriginUser {
    pub date: u64,
    pub sender_user: User,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct MessageOriginHiddenUser {
    pub date: u64,
    pub sender_user_name: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct MessageOriginChat {
    pub date: u64,
    pub sender_chat: Chat,
    pub author_signature: Option<String>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct MessageOriginChannel {
    pub date: u64,
    pub chat: Chat,
    pub message_id: i32,
    pub author_signature: Option<String>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct LinkPreviewOptions {
    pub is_disabled: Option<bool>,
    pub url: Option<String>,
    pub prefer_small_media: Option<bool>,
    pub prefer_large_media: Option<bool>,
    pub show_above_text: Option<bool>,
}

impl LinkPreviewOptions {
    pub const DISABLED: Self = Self {
        is_disabled: Some(true),
        url: None,
        prefer_small_media: None,
        prefer_large_media: None,
        show_above_text: None,
    };
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct SuggestedPostPrice {
    pub currency: String,
    pub amount: u64,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum SuggestedPostState {
    Pending,
    Approved,
    Declined,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct SuggestedPostInfo {
    pub state: SuggestedPostState,
    pub price: Option<SuggestedPostPrice>,
    pub send_date: Option<u64>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct SuggestedPostParameters {
    pub price: Option<SuggestedPostPrice>,
    pub send_date: Option<u64>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct PhotoSize {
    pub file_id: String,
    pub file_unique_id: String,
    pub width: u32,
    pub height: u32,
    pub file_size: Option<u64>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Animation {
    pub file_id: String,
    pub file_unique_id: String,
    pub width: u32,
    pub height: u32,
    pub duration: u32,
    pub thumbnail: Option<PhotoSize>,
    pub file_name: Option<String>,
    pub mime_type: Option<String>,
    pub file_size: Option<u64>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Audio {
    pub file_id: String,
    pub file_unique_id: String,
    pub duration: u32,
    pub performer: Option<String>,
    pub title: Option<String>,
    pub file_name: Option<String>,
    pub mime_type: Option<String>,
    pub file_size: Option<u64>,
    pub thumbnail: Option<PhotoSize>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Document {
    pub file_id: String,
    pub file_unique_id: String,
    pub thumbnail: Option<PhotoSize>,
    pub file_name: Option<String>,
    pub mime_type: Option<String>,
    pub file_size: Option<u64>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct VideoQuality {
    pub file_id: String,
    pub file_unique_id: String,
    pub width: u32,
    pub height: u32,
    pub codec: String,
    pub file_size: Option<u64>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Video {
    pub file_id: String,
    pub file_unique_id: String,
    pub width: u32,
    pub height: u32,
    pub duration: u32,
    pub thumbnail: Option<PhotoSize>,
    pub cover: Option<Vec<PhotoSize>>,
    pub start_timestamp: Option<u64>,
    pub qualities: Option<Vec<VideoQuality>>,
    pub file_name: Option<String>,
    pub mime_type: Option<String>,
    pub file_size: Option<u64>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct VideoNote {
    pub file_id: String,
    pub file_unique_id: String,
    pub length: u32,
    pub duration: u32,
    pub thumbnail: Option<PhotoSize>,
    pub file_size: Option<u64>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Voice {
    pub file_id: String,
    pub file_unique_id: String,
    pub duration: u32,
    pub mime_type: Option<String>,
    pub file_size: Option<u64>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Contact {
    pub phone_number: String,
    pub first_name: String,
    pub last_name: Option<String>,
    pub user_id: Option<u64>,
    pub vcard: Option<String>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Dice {
    pub emoji: String,
    pub value: u8,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct PollOption {
    pub persistent_id: Option<String>,
    pub text: String,
    pub text_entities: Option<Vec<MessageEntity>>,
    pub voter_count: u32,
    pub added_by_user: Option<User>,
    pub added_by_chat: Option<Box<Chat>>,
    pub addition_date: Option<u32>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct InputPollOption {
    pub text: Option<String>,
    pub text_parse_mode: Option<ParseMode>,
    pub text_entities: Option<Vec<MessageEntity>>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct PollAnswer {
    pub poll_id: String,
    pub voter_chat: Option<Chat>,
    pub user: Option<Box<User>>,
    pub option_ids: Vec<u8>,
    pub option_persistent_ids: Vec<String>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Poll {
    pub id: String,
    pub question: String,
    pub question_entities: Option<Vec<MessageEntity>>,
    pub options: Vec<PollOption>,
    pub total_voter_count: u32,
    pub is_closed: bool,
    pub is_anonymous: bool,
    #[serde(rename = "type")]
    pub type_field: PollType,
    pub allows_multiple_answers: Option<bool>,
    pub allows_revoting: Option<bool>,
    pub correct_option_ids: Option<Vec<u8>>,
    pub explanation: Option<String>,
    pub explanation_entities: Option<Vec<MessageEntity>>,
    pub open_period: Option<u32>,
    pub close_date: Option<u64>,
    pub description: Option<String>,
    pub description_entities: Option<Vec<MessageEntity>>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChecklistTask {
    pub id: i64,
    pub text: String,
    pub text_entities: Option<Vec<MessageEntity>>,
    pub completed_by_user: Option<User>,
    pub completed_by_chat: Option<Box<Chat>>,
    pub completion_date: Option<u32>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Checklist {
    pub title: String,
    pub title_entities: Option<Vec<MessageEntity>>,
    pub tasks: Vec<ChecklistTask>,
    pub others_can_add_tasks: Option<bool>,
    pub others_can_mark_tasks_as_done: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct InputChecklistTask {
    pub id: i64,
    pub text: String,
    pub parse_mode: Option<String>,
    pub text_entities: Option<Vec<MessageEntity>>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct InputChecklist {
    pub title: String,
    pub parse_mode: Option<String>,
    pub title_entities: Option<Vec<MessageEntity>>,
    pub tasks: Vec<InputChecklistTask>,
    pub others_can_add_tasks: Option<bool>,
    pub others_can_mark_tasks_as_done: Option<bool>,
}

#[apply(apistruct!)]
pub struct ChecklistTasksDone {
    pub checklist_message: Option<Message>,
    pub marked_as_done_task_ids: Option<Vec<i64>>,
    pub marked_as_not_done_task_ids: Option<Vec<i64>>,
}

#[apply(apistruct!)]
pub struct ChecklistTasksAdded {
    pub checklist_message: Option<Message>,
    pub tasks: Vec<ChecklistTask>,
}

#[apply(apistruct!)]
#[derive(Copy)]
pub struct Location {
    pub longitude: f64,
    pub latitude: f64,
    pub horizontal_accuracy: Option<f64>,
    pub live_period: Option<u32>,
    pub heading: Option<u16>,
    pub proximity_alert_radius: Option<u32>,
}

#[apply(apistruct!)]
pub struct Venue {
    pub location: Location,
    pub title: String,
    pub address: String,
    pub foursquare_id: Option<String>,
    pub foursquare_type: Option<String>,
    pub google_place_id: Option<String>,
    pub google_place_type: Option<String>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ProximityAlertTriggered {
    pub traveler: User,
    pub watcher: User,
    pub distance: u32,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct MessageAutoDeleteTimerChanged {
    pub message_auto_delete_time: u32,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatOwnerLeft {
    pub new_owner: Option<User>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatOwnerChanged {
    pub new_owner: User,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct ChatBoostAdded {
    pub boost_count: u32,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct BackgroundFillSolid {
    pub color: u32,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct BackgroundFillGradient {
    pub top_color: u32,
    pub bottom_color: u32,
    pub rotation_angle: u16,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BackgroundFillFreeformGradient {
    pub colors: Vec<u32>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BackgroundTypeFill {
    pub fill: BackgroundFill,
    pub dark_theme_dimming: u8,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BackgroundTypeWallpaper {
    pub document: Document,
    pub dark_theme_dimming: u8,
    pub is_blurred: Option<bool>,
    pub is_moving: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BackgroundTypePattern {
    pub document: Document,
    pub fill: BackgroundFill,
    pub intensity: u8,
    pub is_inverted: Option<bool>,
    pub is_moving: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BackgroundTypeChatTheme {
    pub theme_name: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ForumTopicCreated {
    pub name: String,
    pub icon_color: u32,
    pub icon_custom_emoji_id: Option<String>,
    pub is_name_implicit: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ForumTopicClosed {}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ForumTopicEdited {
    pub name: Option<String>,
    pub icon_custom_emoji_id: Option<String>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ForumTopicReopened {}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct GeneralForumTopicHidden {}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct GeneralForumTopicUnhidden {}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct SharedUser {
    pub user_id: u64,
    pub first_name: Option<String>,
    pub last_name: Option<String>,
    pub username: Option<String>,
    pub photo: Option<Vec<PhotoSize>>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct UsersShared {
    pub request_id: i32,
    pub users: Vec<SharedUser>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatShared {
    pub request_id: i32,
    pub chat_id: i64,
    pub title: Option<String>,
    pub username: Option<String>,
    pub photo: Option<Vec<PhotoSize>>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct WriteAccessAllowed {
    pub from_request: Option<bool>,
    pub web_app_name: Option<String>,
    pub from_attachment_menu: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct VideoChatEnded {
    pub duration: u32,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct VideoChatParticipantsInvited {
    pub users: Option<Vec<User>>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct DirectMessagesTopic {
    pub topic_id: i64,
    pub user: Option<User>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct UserProfilePhotos {
    pub total_count: u32,
    pub photos: Vec<Vec<PhotoSize>>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct UserProfileAudios {
    pub total_count: u32,
    pub audios: Vec<Audio>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct File {
    pub file_id: String,
    pub file_unique_id: String,
    pub file_size: Option<u64>,
    pub file_path: Option<String>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ReplyKeyboardMarkup {
    pub keyboard: Vec<Vec<KeyboardButton>>,
    pub is_persistent: Option<bool>,
    pub resize_keyboard: Option<bool>,
    pub one_time_keyboard: Option<bool>,
    pub input_field_placeholder: Option<String>,
    pub selective: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct KeyboardButton {
    pub text: String,
    pub icon_custom_emoji_id: Option<String>,
    pub request_users: Option<KeyboardButtonRequestUsers>,
    pub request_chat: Option<KeyboardButtonRequestChat>,
    pub request_managed_bot: Option<KeyboardButtonRequestManagedBot>,
    pub request_contact: Option<bool>,
    pub request_location: Option<bool>,
    pub request_poll: Option<KeyboardButtonPollType>,
    pub web_app: Option<WebAppInfo>,
    pub style: Option<ButtonStyle>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct KeyboardButtonRequestUsers {
    pub request_id: i32,
    pub user_is_bot: Option<bool>,
    pub user_is_premium: Option<bool>,
    pub max_quantity: Option<u32>,
    pub request_name: Option<bool>,
    pub request_username: Option<bool>,
    pub request_photo: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct KeyboardButtonRequestChat {
    pub request_id: i32,
    pub chat_is_channel: bool,
    pub chat_is_forum: Option<bool>,
    pub chat_has_username: Option<bool>,
    pub chat_is_created: Option<bool>,
    pub user_administrator_rights: Option<ChatAdministratorRights>,
    pub bot_administrator_rights: Option<ChatAdministratorRights>,
    pub bot_is_member: Option<bool>,
    pub request_title: Option<bool>,
    pub request_username: Option<bool>,
    pub request_photo: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct KeyboardButtonRequestManagedBot {
    pub request_id: i32,
    pub suggested_name: Option<String>,
    pub suggested_username: Option<String>,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct KeyboardButtonPollType {
    #[serde(rename = "type")]
    pub type_field: Option<PollType>,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct ReplyKeyboardRemove {
    pub remove_keyboard: bool,
    pub selective: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct InlineKeyboardMarkup {
    pub inline_keyboard: Vec<Vec<InlineKeyboardButton>>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct InlineKeyboardButton {
    pub text: String,
    pub icon_custom_emoji_id: Option<String>,
    pub url: Option<String>,
    pub login_url: Option<LoginUrl>,
    pub callback_data: Option<String>,
    pub web_app: Option<WebAppInfo>,
    pub switch_inline_query: Option<String>,
    pub switch_inline_query_current_chat: Option<String>,
    pub switch_inline_query_chosen_chat: Option<SwitchInlineQueryChosenChat>,
    pub copy_text: Option<CopyTextButton>,
    pub callback_game: Option<CallbackGame>,
    pub pay: Option<bool>,
    pub style: Option<ButtonStyle>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct LoginUrl {
    pub url: String,
    pub forward_text: Option<String>,
    pub bot_username: Option<String>,
    pub request_write_access: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct SwitchInlineQueryChosenChat {
    pub query: Option<String>,
    pub allow_user_chats: Option<bool>,
    pub allow_bot_chats: Option<bool>,
    pub allow_group_chats: Option<bool>,
    pub allow_channel_chats: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct CopyTextButton {
    pub text: String,
}

#[apply(apistruct!)]
pub struct CallbackQuery {
    pub id: String,
    pub from: User,
    pub message: Option<MaybeInaccessibleMessage>,
    pub inline_message_id: Option<String>,
    pub chat_instance: String,
    pub data: Option<String>,
    pub game_short_name: Option<String>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ForceReply {
    pub force_reply: bool,
    pub input_field_placeholder: Option<String>,
    pub selective: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatPhoto {
    pub small_file_id: String,
    pub small_file_unique_id: String,
    pub big_file_id: String,
    pub big_file_unique_id: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatInviteLink {
    pub invite_link: String,
    pub creator: User,
    pub creates_join_request: bool,
    pub is_primary: bool,
    pub is_revoked: bool,
    pub name: Option<String>,
    pub expire_date: Option<u64>,
    pub member_limit: Option<u32>,
    pub pending_join_request_count: Option<u32>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatMemberUpdated {
    pub chat: Chat,
    pub from: User,
    pub date: u64,
    pub old_chat_member: ChatMember,
    pub new_chat_member: ChatMember,
    pub invite_link: Option<ChatInviteLink>,
    pub via_join_request: Option<bool>,
    pub via_chat_folder_invite_link: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatJoinRequest {
    pub chat: Chat,
    pub from: User,
    pub user_chat_id: u64,
    pub date: u64,
    pub bio: Option<String>,
    pub invite_link: Option<ChatInviteLink>,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct ChatPermissions {
    pub can_send_messages: Option<bool>,
    pub can_send_audios: Option<bool>,
    pub can_send_documents: Option<bool>,
    pub can_send_photos: Option<bool>,
    pub can_send_videos: Option<bool>,
    pub can_send_video_notes: Option<bool>,
    pub can_send_voice_notes: Option<bool>,
    pub can_send_polls: Option<bool>,
    pub can_send_other_messages: Option<bool>,
    pub can_add_web_page_previews: Option<bool>,
    pub can_edit_tag: Option<bool>,
    pub can_change_info: Option<bool>,
    pub can_invite_users: Option<bool>,
    pub can_pin_messages: Option<bool>,
    pub can_manage_topics: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Birthdate {
    pub day: u8,
    pub month: u8,
    pub year: Option<u16>,
}

#[apply(apistruct!)]
pub struct BusinessIntro {
    pub title: Option<String>,
    pub message: Option<String>,
    pub sticker: Option<Sticker>,
}

#[apply(apistruct!)]
pub struct BusinessLocation {
    pub address: String,
    pub location: Option<Location>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BusinessOpeningHoursInterval {
    pub opening_minute: u16,
    pub closing_minute: u16,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BusinessOpeningHours {
    pub time_zone_name: String,
    pub opening_hours: Vec<BusinessOpeningHoursInterval>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct UserRating {
    pub level: i32,
    pub rating: i32,
    pub current_level_rating: i32,
    pub next_level_rating: Option<i32>,
}

#[apply(apistruct!)]
pub struct StoryAreaPosition {
    pub x_percentage: f64,
    pub y_percentage: f64,
    pub width_percentage: f64,
    pub height_percentage: f64,
    pub rotation_angle: f64,
    pub corner_radius_percentage: f64,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct LocationAddress {
    pub country_code: String,
    pub state: Option<String>,
    pub city: Option<String>,
    pub street: Option<String>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum StoryAreaType {
    Location(StoryAreaTypeLocation),
    SuggestedReaction(StoryAreaTypeSuggestedReaction),
    Link(StoryAreaTypeLink),
    Weather(StoryAreaTypeWeather),
    UniqueGift(StoryAreaTypeUniqueGift),
}

#[apply(apistruct!)]
pub struct StoryAreaTypeLocation {
    pub latitude: f64,
    pub longitude: f64,
    pub address: Option<LocationAddress>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct StoryAreaTypeSuggestedReaction {
    pub reaction_type: ReactionType,
    pub is_dark: Option<bool>,
    pub is_flipped: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct StoryAreaTypeLink {
    pub url: String,
}

#[apply(apistruct!)]
pub struct StoryAreaTypeWeather {
    pub temperature: f64,
    pub emoji: String,
    pub background_color: i64,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct StoryAreaTypeUniqueGift {
    pub name: String,
}

#[apply(apistruct!)]
pub struct StoryArea {
    pub position: StoryAreaPosition,
    #[serde(rename = "type")]
    pub type_field: StoryAreaType,
}

#[apply(apistruct!)]
pub struct ChatLocation {
    pub location: Location,
    pub address: String,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ReactionType {
    Emoji(ReactionTypeEmoji),
    CustomEmoji(ReactionTypeCustomEmoji),
    Paid(ReactionTypePaid),
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ReactionTypeEmoji {
    pub emoji: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ReactionTypeCustomEmoji {
    pub custom_emoji_id: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ReactionTypePaid {}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ReactionCount {
    #[serde(rename = "type")]
    pub type_field: ReactionType,
    pub total_count: i32,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct MessageReactionUpdated {
    pub chat: Chat,
    pub message_id: i32,
    pub user: Option<User>,
    pub actor_chat: Option<Chat>,
    pub date: u64,
    pub old_reaction: Vec<ReactionType>,
    pub new_reaction: Vec<ReactionType>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct MessageReactionCountUpdated {
    pub chat: Chat,
    pub message_id: i32,
    pub date: u64,
    pub reactions: Vec<ReactionCount>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ForumTopic {
    pub message_thread_id: i32,
    pub name: String,
    pub icon_color: u32,
    pub icon_custom_emoji_id: Option<String>,
    pub is_name_implicit: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BotCommand {
    pub command: String,
    pub description: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Story {
    pub chat: Chat,
    pub id: u64,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct PaidMediaInfo {
    pub star_count: u32,
    pub paid_media: Vec<PaidMedia>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum PaidMedia {
    Preview(PaidMediaPreview),
    Photo(PaidMediaPhoto),
    Video(Box<PaidMediaVideo>),
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct PaidMediaPreview {
    pub width: Option<u32>,
    pub height: Option<u32>,
    pub duration: Option<u32>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct PaidMediaPhoto {
    pub photo: Vec<PhotoSize>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct PaidMediaVideo {
    pub video: Video,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct PaidMessagePriceChanged {
    pub paid_message_star_count: u32,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct DirectMessagePriceChanged {
    pub are_direct_messages_enabled: bool,
    pub direct_message_star_count: Option<u32>,
}

#[apply(apistruct!)]
pub struct SuggestedPostApproved {
    pub suggested_post_message: Option<Message>,
    pub price: Option<SuggestedPostPrice>,
    pub send_date: u64,
}

#[apply(apistruct!)]
pub struct SuggestedPostApprovalFailed {
    pub suggested_post_message: Option<Message>,
    pub price: SuggestedPostPrice,
}

#[apply(apistruct!)]
pub struct SuggestedPostDeclined {
    pub suggested_post_message: Option<Message>,
    pub comment: Option<String>,
}

#[apply(apistruct!)]
pub struct SuggestedPostPaid {
    pub suggested_post_message: Option<Message>,
    pub currency: String,
    pub amount: Option<u64>,
    pub star_amount: Option<StarAmount>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RefundReason {
    PostDeleted,
    PaymentRefunded,
}

#[apply(apistruct!)]
pub struct SuggestedPostRefunded {
    pub suggested_post_message: Option<Message>,
    pub reason: RefundReason,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct GiveawayCreated {
    pub prize_star_count: Option<u32>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct Giveaway {
    pub chats: Vec<Chat>,
    pub winners_selection_date: u64,
    pub winner_count: u32,
    pub only_new_members: Option<bool>,
    pub has_public_winners: Option<bool>,
    pub prize_description: Option<String>,
    pub country_codes: Option<Vec<String>>,
    pub prize_star_count: Option<u32>,
    pub premium_subscription_month_count: Option<u32>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct GiveawayWinners {
    pub chat: Chat,
    pub giveaway_message_id: i32,
    pub winners_selection_date: u64,
    pub winner_count: u32,
    pub winners: Vec<User>,
    pub additional_chat_count: Option<u32>,
    pub prize_star_count: Option<u32>,
    pub premium_subscription_month_count: Option<u32>,
    pub unclaimed_prize_count: Option<u32>,
    pub only_new_members: Option<bool>,
    pub was_refunded: Option<bool>,
    pub prize_description: Option<String>,
}

#[apply(apistruct!)]
pub struct GiveawayCompleted {
    pub winner_count: u32,
    pub unclaimed_prize_count: Option<u32>,
    pub giveaway_message: Option<Box<Message>>,
    pub is_star_giveaway: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Copy, Eq)]
pub struct ChatAdministratorRights {
    pub is_anonymous: bool,
    pub can_manage_chat: bool,
    pub can_delete_messages: bool,
    pub can_manage_video_chats: bool,
    pub can_restrict_members: bool,
    pub can_promote_members: bool,
    pub can_change_info: bool,
    pub can_invite_users: bool,
    pub can_post_messages: Option<bool>,
    pub can_edit_messages: Option<bool>,
    pub can_pin_messages: Option<bool>,
    pub can_post_stories: Option<bool>,
    pub can_edit_stories: Option<bool>,
    pub can_delete_stories: Option<bool>,
    pub can_manage_topics: Option<bool>,
    pub can_manage_direct_messages: Option<bool>,
    pub can_manage_tags: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct WebAppInfo {
    pub url: String,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct WebAppData {
    pub data: String,
    pub button_text: String,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "source", rename_all = "snake_case")]
pub enum ChatBoostSource {
    Premium(ChatBoostSourcePremium),
    GiftCode(ChatBoostSourceGiftCode),
    Giveaway(ChatBoostSourceGiveaway),
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatBoostSourcePremium {
    pub user: User,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatBoostSourceGiftCode {
    pub user: User,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatBoostSourceGiveaway {
    pub giveaway_message_id: i32,
    pub user: Option<User>,
    pub prize_star_count: Option<u32>,
    pub is_unclaimed: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatBoost {
    pub boost_id: String,
    pub add_date: u64,
    pub expiration_date: u64,
    pub source: ChatBoostSource,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatBoostUpdated {
    pub chat: Chat,
    pub boost: ChatBoost,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ChatBoostRemoved {
    pub chat: Chat,
    pub boost_id: String,
    pub remove_date: u64,
    pub source: ChatBoostSource,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct UserChatBoosts {
    pub boosts: Vec<ChatBoost>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BusinessConnection {
    pub id: String,
    pub user: User,
    pub user_chat_id: u64,
    pub date: u64,
    pub rights: Option<BusinessBotRights>,
    pub is_enabled: bool,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BusinessBotRights {
    pub can_reply: Option<bool>,
    pub can_read_messages: Option<bool>,
    pub can_delete_sent_messages: Option<bool>,
    pub can_delete_all_messages: Option<bool>,
    pub can_edit_name: Option<bool>,
    pub can_edit_bio: Option<bool>,
    pub can_edit_profile_photo: Option<bool>,
    pub can_edit_username: Option<bool>,
    pub can_change_gift_settings: Option<bool>,
    pub can_view_gifts_and_stars: Option<bool>,
    pub can_convert_gifts_to_stars: Option<bool>,
    pub can_transfer_and_upgrade_gifts: Option<bool>,
    pub can_transfer_stars: Option<bool>,
    pub can_manage_stories: Option<bool>,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct BusinessMessagesDeleted {
    pub business_connection_id: String,
    pub chat: Chat,
    pub message_ids: Vec<i32>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum MaybeInaccessibleMessage {
    Message(Box<Message>),
    InaccessibleMessage(InaccessibleMessage),
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct InaccessibleMessage {
    pub chat: Chat,
    pub message_id: i32,
    pub date: u64,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ManagedBotCreated {
    pub bot: User,
}

#[apply(apistruct!)]
#[derive(Eq)]
pub struct ManagedBotUpdated {
    pub user: User,
    pub bot: User,
}

#[apply(apistruct!)]
pub struct PollOptionAdded {
    pub poll_message: Option<MaybeInaccessibleMessage>,
    pub option_persistent_id: String,
    pub option_text: String,
    pub option_text_entities: Option<Vec<MessageEntity>>,
}

#[apply(apistruct!)]
pub struct PollOptionDeleted {
    pub poll_message: Option<MaybeInaccessibleMessage>,
    pub option_persistent_id: String,
    pub option_text: String,
    pub option_text_entities: Option<Vec<MessageEntity>>,
}

#[cfg(test)]
mod serde_tests {
    use super::*;

    #[test]
    pub fn kicked_user_status_is_parsed() {
        let member_content = r#"{
            "status": "kicked",
            "until_date": 0,
            "user": {
                "id": 0,
                "is_bot": false,
                "first_name": "First"
            }
        }"#;

        let member: ChatMember = serde_json::from_str(member_content).unwrap();
        assert!(matches!(member, ChatMember::Kicked(_)));
    }

    #[test]
    pub fn unknown_entity_kind_is_parsed() {
        let entity_content = r#"{
            "type": "__unknown__",
            "offset": 10,
            "length": 20
        }"#;

        let entity: MessageEntity = serde_json::from_str(entity_content).unwrap();
        assert!(matches!(
            entity,
            MessageEntity {
                type_field: MessageEntityType::Unknown,
                ..
            }
        ));
    }
}