teloxide_tests 0.4.0

Test suite for teloxide bots
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
use core::sync::atomic::{AtomicI32, Ordering};

use chrono::{DateTime, Utc};
use mime::Mime;
use teloxide::types::*;

use super::{
    chat::MockPrivateChat, message::Message, MockLocation, MockPhotoSize, MockUser, MockVideo,
};
use crate::proc_macros::Changeable;

macro_rules! MessageCommon {  // Rust was supposed to be used without inheritance, and yet here i am, reinventing it...
    (
        #[derive($($derive:meta),*)]
        $pub:vis struct $name:ident {
            $($fpub:vis $field:ident : $type:ty,)*
        }
    ) => {
        Message! {  // DRY is dangerous. This looks scary.
            #[derive($($derive),*)]
            $pub struct $name {
                pub author_signature: Option<String>,
                pub paid_star_count: Option<u32>,
                pub effect_id: Option<EffectId>,
                pub forward_origin: Option<MessageOrigin>,
                pub reply_to_message: Option<Box<Message>>,
                pub external_reply: Option<ExternalReplyInfo>,
                pub quote: Option<TextQuote>,
                pub edit_date: Option<DateTime<Utc>>,
                pub reply_markup: Option<InlineKeyboardMarkup>,
                pub is_automatic_forward: bool,
                pub has_protected_content: bool,
                pub is_from_offline: bool,
                pub business_connection_id: Option<BusinessConnectionId>,
                pub reply_to_story: Option<Story>,
                pub sender_boost_count: Option<u16>,

                $($fpub $field : $type,)*  // Just all of the other fields, nothig too scary here
            }
        }
        impl $name {  // Implements common functions
            pub const IS_AUTOMATIC_FORWARD: bool = false;
            pub const HAS_PROTECTED_CONTENT: bool = false;
            pub const IS_FROM_OFFLINE: bool = false;

            pub(crate) fn new_message_common($($field:$type,)*) -> Self {
                 $name::new_message(
                     None,
                     None,
                     None,
                     None,
                     None,
                     None,
                     None,
                     None,
                     None,
                     $name::IS_AUTOMATIC_FORWARD,
                     $name::HAS_PROTECTED_CONTENT,
                     $name::IS_FROM_OFFLINE,
                     None,
                     None,
                     None,
                     $($field,)*  // All of the other fields from the child struct
                 )
            }

            pub(crate) fn build_message_common(self, media_kind: MediaKind) -> Message {
                self.clone().build_message(MessageKind::Common(MessageCommon {
                    author_signature: self.author_signature,
                    paid_star_count: self.paid_star_count,
                    effect_id: self.effect_id,
                    forward_origin: self.forward_origin,
                    reply_to_message: self.reply_to_message,
                    external_reply: self.external_reply,
                    quote: self.quote,
                    edit_date: self.edit_date,
                    reply_markup: self.reply_markup,
                    media_kind,
                    is_automatic_forward: self.is_automatic_forward,
                    has_protected_content: self.has_protected_content,
                    business_connection_id: self.business_connection_id,
                    is_from_offline: self.is_from_offline,
                    reply_to_story: self.reply_to_story,
                    sender_boost_count: self.sender_boost_count,
                }))
            }
        }
    }
}

/*


        Structs below are just copies of MessageCommon with different MediaKinds, with some flattening of arguments where suitable.

        So boring they could've been autogenerated


*/

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageText {
        pub text: String,
        pub entities: Vec<MessageEntity>,
        pub link_preview_options: Option<LinkPreviewOptions>,
    }
}

impl MockMessageText {
    pub const TEXT: &'static str = "text";

    /// Creates a new easily changable message text builder
    ///
    /// # Example
    /// ```
    /// let message = teloxide_tests::MockMessageText::new()
    ///     .text("/start")
    ///     .build();
    /// assert_eq!(message.text().unwrap(), "/start");
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(Self::TEXT.to_string(), vec![], None)
    }

    /// Builds the message text
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageText::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.text().unwrap(), teloxide_tests::MockMessageText::TEXT.to_string());  // TEXT is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Text(MediaText {
                text: self.text,
                entities: self.entities,
                link_preview_options: self.link_preview_options,
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageAnimation {
        pub caption: Option<String>,
        pub caption_entities: Vec<MessageEntity>,
        pub show_caption_above_media: bool,
        pub has_media_spoiler: bool,
        // Animation
        pub width: u32,
        pub height: u32,
        pub duration: Seconds,
        pub thumbnail: Option<PhotoSize>,
        pub file_name: Option<String>,
        pub mime_type: Option<Mime>,
        // FileMeta
        pub file_id: FileId,
        pub file_unique_id: FileUniqueId,
        pub file_size: u32,
    }
}

impl MockMessageAnimation {
    pub const HAS_MEDIA_SPOILER: bool = false;
    pub const SHOW_CAPTION_ABOVE_MEDIA: bool = false;
    pub const WIDTH: u32 = 50;
    pub const HEIGHT: u32 = 50;
    pub const DURATION: Seconds = Seconds::from_seconds(60);
    pub const FILE_ID: &'static str = "file_id";
    pub const UNIQUE_FILE_ID: &'static str = "file_unique_id";
    pub const FILE_SIZE: u32 = 50;

    /// Creates a new easily changable message animation builder
    ///
    /// # Example
    /// ```
    /// let message = teloxide_tests::MockMessageAnimation::new()
    ///     .has_media_spoiler(true)
    ///     .build();
    /// assert_eq!(message.has_media_spoiler(), true);
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            None,
            vec![],
            Self::SHOW_CAPTION_ABOVE_MEDIA,
            Self::HAS_MEDIA_SPOILER,
            Self::WIDTH,
            Self::HEIGHT,
            Self::DURATION,
            None,
            None,
            None,
            Self::FILE_ID.into(),
            Self::UNIQUE_FILE_ID.into(),
            Self::FILE_SIZE,
        )
    }

    /// Builds the message animation
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageAnimation::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.has_media_spoiler(), teloxide_tests::MockMessageAnimation::HAS_MEDIA_SPOILER);  // HAS_MEDIA_SPOILER is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Animation(MediaAnimation {
                caption: self.caption,
                caption_entities: self.caption_entities,
                show_caption_above_media: self.show_caption_above_media,
                has_media_spoiler: self.has_media_spoiler,
                animation: Animation {
                    file: FileMeta {
                        id: self.file_id,
                        unique_id: self.file_unique_id,
                        size: self.file_size,
                    },
                    width: self.width,
                    height: self.height,
                    duration: self.duration,
                    thumbnail: self.thumbnail,
                    file_name: self.file_name,
                    mime_type: self.mime_type,
                },
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageAudio {
        pub caption: Option<String>,
        pub caption_entities: Vec<MessageEntity>,
        pub media_group_id: Option<MediaGroupId>,
        // Audio
        pub duration: Seconds,
        pub performer: Option<String>,
        pub title: Option<String>,
        pub thumbnail: Option<PhotoSize>,
        pub file_name: Option<String>,
        pub mime_type: Option<Mime>,
        // FileMeta
        pub file_id: FileId,
        pub file_unique_id: FileUniqueId,
        pub file_size: u32,
    }
}

impl MockMessageAudio {
    pub const DURATION: Seconds = Seconds::from_seconds(236);
    pub const FILE_ID: &'static str = "CQADAgADbQEAAsnrIUpNoRRNsH7_hAI";
    pub const UNIQUE_FILE_ID: &'static str = "file_unique_id";
    pub const FILE_SIZE: u32 = 9507774;

    /// Creates a new easily changable message audio builder
    ///
    /// # Example
    /// ```
    /// use teloxide::types::Seconds;
    /// let message = teloxide_tests::MockMessageAudio::new()
    ///     .duration(Seconds::from_seconds(236))
    ///     .build();
    /// assert_eq!(message.audio().unwrap().duration, Seconds::from_seconds(236));
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            None,
            vec![],
            None,
            Self::DURATION,
            None,
            None,
            None,
            None,
            None,
            Self::FILE_ID.into(),
            Self::UNIQUE_FILE_ID.into(),
            Self::FILE_SIZE,
        )
    }

    /// Builds the message audio
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageAudio::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.audio().unwrap().duration, teloxide_tests::MockMessageAudio::DURATION);  // DURATION is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Audio(MediaAudio {
                caption: self.caption,
                caption_entities: self.caption_entities,
                media_group_id: self.media_group_id,
                audio: Audio {
                    file: FileMeta {
                        id: self.file_id,
                        unique_id: self.file_unique_id,
                        size: self.file_size,
                    },
                    duration: self.duration,
                    performer: self.performer,
                    title: self.title,
                    thumbnail: self.thumbnail,
                    file_name: self.file_name,
                    mime_type: self.mime_type,
                },
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageContact {
        pub phone_number: String,
        pub first_name: String,
        pub last_name: Option<String>,
        pub user_id: Option<UserId>,
        pub vcard: Option<String>,
    }
}

impl MockMessageContact {
    pub const PHONE_NUMBER: &'static str = "+123456789";
    pub const FIRST_NAME: &'static str = "First";

    /// Creates a new easily changable message contact builder
    ///
    /// # Example
    /// ```
    /// let message = teloxide_tests::MockMessageContact::new()
    ///     .phone_number("+123456789")
    ///     .build();
    /// assert_eq!(message.contact().unwrap().phone_number, "+123456789");  // PHONE_NUMBER is a default value
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            Self::PHONE_NUMBER.to_string(),
            Self::FIRST_NAME.to_string(),
            None,
            None,
            None,
        )
    }

    /// Builds the message contact
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageContact::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.contact().unwrap().phone_number, teloxide_tests::MockMessageContact::PHONE_NUMBER);  // PHONE_NUMBER is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Contact(MediaContact {
                contact: Contact {
                    phone_number: self.phone_number,
                    first_name: self.first_name,
                    last_name: self.last_name,
                    user_id: self.user_id,
                    vcard: self.vcard,
                },
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageDocument {
        pub caption: Option<String>,
        pub caption_entities: Vec<MessageEntity>,
        pub media_group_id: Option<MediaGroupId>,
        // Document
        pub thumbnail: Option<PhotoSize>,
        pub file_name: Option<String>,
        pub mime_type: Option<Mime>,
        // FileMeta
        pub file_id: FileId,
        pub file_unique_id: FileUniqueId,
        pub file_size: u32,
    }
}

impl MockMessageDocument {
    pub const FILE_ID: &'static str = "BQADAgADpgADy_JxS66XQTBRHFleAg";
    pub const UNIQUE_FILE_ID: &'static str = "file_unique_id";
    pub const FILE_SIZE: u32 = 21331;

    /// Creates a new easily changable message document builder
    ///
    /// # Example
    /// ```
    /// let message = teloxide_tests::MockMessageDocument::new()
    ///     .file_id("12345".into())
    ///     .build();
    /// assert_eq!(message.document().unwrap().file.id, "12345".into());  // FILE_ID is a default value
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            None,
            vec![],
            None,
            None,
            None,
            None,
            Self::FILE_ID.into(),
            Self::UNIQUE_FILE_ID.into(),
            Self::FILE_SIZE,
        )
    }

    /// Builds the message document
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageDocument::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.document().unwrap().file.id, teloxide_tests::MockMessageDocument::FILE_ID.into());  // FILE_ID is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Document(MediaDocument {
                caption: self.caption,
                caption_entities: self.caption_entities,
                media_group_id: self.media_group_id,
                document: Document {
                    file: FileMeta {
                        id: self.file_id,
                        unique_id: self.file_unique_id,
                        size: self.file_size,
                    },
                    thumbnail: self.thumbnail,
                    file_name: self.file_name,
                    mime_type: self.mime_type,
                },
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageGame {
        pub title: String,
        pub description: String,
        pub photo: Vec<PhotoSize>,
        pub text: Option<String>,
        pub text_entities: Option<Vec<MessageEntity>>,
        pub animation: Option<Animation>,
    }
}

impl MockMessageGame {
    pub const TITLE: &'static str = "Title";
    pub const DESCRIPTION: &'static str = "Description";

    /// Creates a new easily changable message game builder
    ///
    /// # Example
    /// ```
    /// let message = teloxide_tests::MockMessageGame::new()
    ///     .title("title")
    ///     .build();
    /// assert_eq!(message.game().unwrap().title, "title");  // TITLE is a default value
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            Self::TITLE.to_string(),
            Self::DESCRIPTION.to_string(),
            vec![MockPhotoSize::new().build()],
            None,
            None,
            None,
        )
    }

    /// Builds the message game
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageGame::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.game().unwrap().title, teloxide_tests::MockMessageGame::TITLE);  // TITLE is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Game(MediaGame {
                game: Game {
                    title: self.title,
                    description: self.description,
                    photo: self.photo,
                    text: self.text,
                    text_entities: self.text_entities,
                    animation: self.animation,
                },
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageVenue {
        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>,
    }
}

impl MockMessageVenue {
    pub const TITLE: &'static str = "Title";
    pub const ADDRESS: &'static str = "Address";

    /// Creates a new easily changable message venue builder
    ///
    /// # Example
    /// ```
    /// let message = teloxide_tests::MockMessageVenue::new()
    ///     .title("title")
    ///     .build();
    /// assert_eq!(message.venue().unwrap().title, "title");  // TITLE is a default value
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            MockLocation::new().build(),
            Self::TITLE.to_string(),
            Self::ADDRESS.to_string(),
            None,
            None,
            None,
            None,
        )
    }

    /// Builds the message venue
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageVenue::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.venue().unwrap().title, teloxide_tests::MockMessageVenue::TITLE);  // TITLE is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Venue(MediaVenue {
                venue: Venue {
                    location: self.location,
                    title: self.title,
                    address: self.address,
                    foursquare_id: self.foursquare_id,
                    foursquare_type: self.foursquare_type,
                    google_place_id: self.google_place_id,
                    google_place_type: self.google_place_type,
                },
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageLocation {
        pub latitude: f64,
        pub longitude: f64,
        pub horizontal_accuracy: Option<f64>,
        pub live_period: Option<LivePeriod>,
        pub heading: Option<u16>,
        pub proximity_alert_radius: Option<u32>,
    }
}

impl MockMessageLocation {
    pub const LATITUDE: f64 = 50.0;
    pub const LONGITUDE: f64 = 30.0;

    /// Creates a new easily changable message location builder
    ///
    /// # Example
    /// ```
    /// let message = teloxide_tests::MockMessageLocation::new()
    ///     .latitude(50.0)
    ///     .build();
    /// assert_eq!(message.location().unwrap().latitude, 50.0);  // LATITUDE is a default value
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(Self::LATITUDE, Self::LONGITUDE, None, None, None, None)
    }

    /// Builds the message location
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageLocation::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.location().unwrap().latitude, teloxide_tests::MockMessageLocation::LATITUDE);  // LATITUDE is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Location(MediaLocation {
                location: Location {
                    longitude: self.longitude,
                    latitude: self.latitude,
                    horizontal_accuracy: self.horizontal_accuracy,
                    live_period: self.live_period,
                    heading: self.heading,
                    proximity_alert_radius: self.proximity_alert_radius,
                },
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessagePhoto {
        pub caption: Option<String>,
        pub caption_entities: Vec<MessageEntity>,
        pub media_group_id: Option<MediaGroupId>,
        pub show_caption_above_media: bool,
        pub has_media_spoiler: bool,
        pub photo: Vec<PhotoSize>,
    }
}

impl MockMessagePhoto {
    pub const HAS_MEDIA_SPOILER: bool = false;
    pub const SHOW_CAPTION_ABOVE_MEDIA: bool = false;

    /// Creates a new easily changable message photo builder
    ///
    /// # Example
    /// ```
    /// let message = teloxide_tests::MockMessagePhoto::new()
    ///     .has_media_spoiler(true)
    ///     .photo(vec![teloxide_tests::MockPhotoSize::new().build(); 3])
    ///     .build();
    /// assert_eq!(message.has_media_spoiler(), true);
    /// assert_eq!(message.photo().unwrap().len(), 3);
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            None,
            vec![],
            None,
            Self::SHOW_CAPTION_ABOVE_MEDIA,
            Self::HAS_MEDIA_SPOILER,
            vec![MockPhotoSize::new().build()],
        )
    }

    /// Builds the message photo
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessagePhoto::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.photo().unwrap().len(), 1);  // By default, there is only one photo, just MockPhotoSize::new().build()
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Photo(MediaPhoto {
                caption: self.caption,
                caption_entities: self.caption_entities,
                media_group_id: self.media_group_id,
                show_caption_above_media: self.show_caption_above_media,
                has_media_spoiler: self.has_media_spoiler,
                photo: self.photo,
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessagePoll {
        pub poll_id: PollId,
        pub question: String,
        pub question_entities: Option<Vec<MessageEntity>>,
        pub options: Vec<PollOption>,
        pub is_closed: bool,
        pub total_voter_count: u32,
        pub is_anonymous: bool,
        pub poll_type: PollType,
        pub allows_multiple_answers: bool,
        pub correct_option_id: Option<u8>,
        pub explanation: Option<String>,
        pub explanation_entities: Option<Vec<MessageEntity>>,
        pub open_period: Option<Seconds>,
        pub close_date: Option<DateTime<Utc>>,
    }
}

impl MockMessagePoll {
    pub const POLL_ID: &'static str = "12345";
    pub const QUESTION: &'static str = "Question";
    pub const IS_CLOSED: bool = true;
    pub const IS_ANONYMOUS: bool = true;
    pub const TOTAL_VOTER_COUNT: u32 = 50;
    pub const POLL_TYPE: PollType = PollType::Regular;
    pub const ALLOW_MULTIPLE_ANSWERS: bool = true;

    /// Creates a new easily changable message poll builder
    ///
    /// # Example
    /// ```
    /// let message = teloxide_tests::MockMessagePoll::new()
    ///     .poll_id("123456".into())
    ///     .build();
    ///
    /// assert_eq!(message.poll().unwrap().id, "123456".into());
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            Self::POLL_ID.into(),
            Self::QUESTION.to_string(),
            None,
            vec![],
            Self::IS_CLOSED,
            Self::TOTAL_VOTER_COUNT,
            Self::IS_ANONYMOUS,
            Self::POLL_TYPE,
            Self::ALLOW_MULTIPLE_ANSWERS,
            None,
            None,
            None,
            None,
            None,
        )
    }

    /// Builds the message poll
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessagePoll::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.poll().unwrap().id, teloxide_tests::MockMessagePoll::POLL_ID.into()); // POLL_ID is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Poll(MediaPoll {
                poll: Poll {
                    id: self.poll_id,
                    question: self.question,
                    question_entities: self.question_entities,
                    options: self.options,
                    is_closed: self.is_closed,
                    total_voter_count: self.total_voter_count,
                    is_anonymous: self.is_anonymous,
                    poll_type: self.poll_type,
                    allows_multiple_answers: self.allows_multiple_answers,
                    correct_option_id: self.correct_option_id,
                    explanation: self.explanation,
                    explanation_entities: self.explanation_entities,
                    open_period: self.open_period,
                    close_date: self.close_date,
                },
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageSticker {
        pub width: u16,
        pub height: u16,
        pub kind: StickerKind,
        pub flags: StickerFormatFlags,
        pub thumbnail: Option<PhotoSize>,
        pub emoji: Option<String>,
        pub set_name: Option<String>,
        pub needs_repainting: bool,
        // File meta
        pub file_id: FileId,
        pub file_unique_id: FileUniqueId,
        pub file_size: u32,
    }
}

impl MockMessageSticker {
    pub const WIDTH: u16 = 512;
    pub const HEIGHT: u16 = 512;
    pub const KIND: StickerKind = StickerKind::Regular {
        premium_animation: None,
    };
    pub const FILE_ID: &'static str = "AAbbCCddEEffGGhh1234567890";
    pub const FILE_UNIQUE_ID: &'static str = "file_unique_id";
    pub const FILE_SIZE: u32 = 12345;

    /// Creates a new easily changable message sticker builder
    ///
    /// # Example
    /// ```
    /// let message = teloxide_tests::MockMessageSticker::new().file_id("12345".into()).build();
    ///
    /// assert_eq!(message.sticker().unwrap().file.id, "12345".into());
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            Self::WIDTH,
            Self::HEIGHT,
            Self::KIND,
            StickerFormatFlags {
                is_animated: false,
                is_video: false,
            },
            None,
            None,
            None,
            false,
            Self::FILE_ID.into(),
            Self::FILE_UNIQUE_ID.into(),
            Self::FILE_SIZE,
        )
    }

    /// Builds the message sticker
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageSticker::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.sticker().unwrap().file.id, teloxide_tests::MockMessageSticker::FILE_ID.into()); // FILE_ID is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Sticker(MediaSticker {
                sticker: Sticker {
                    file: FileMeta {
                        id: self.file_id,
                        unique_id: self.file_unique_id,
                        size: self.file_size,
                    },
                    width: self.width,
                    height: self.height,
                    kind: self.kind,
                    flags: self.flags,
                    thumbnail: self.thumbnail,
                    emoji: self.emoji,
                    set_name: self.set_name,
                    needs_repainting: self.needs_repainting,
                },
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageVideo {
        pub caption: Option<String>,
        pub caption_entities: Vec<MessageEntity>,
        pub media_group_id: Option<MediaGroupId>,
        pub show_caption_above_media: bool,
        pub has_media_spoiler: bool,
        pub video: Video,
    }
}

impl MockMessageVideo {
    pub const HAS_MEDIA_SPOILER: bool = false;
    pub const SHOW_CAPTION_ABOVE_MEDIA: bool = false;

    /// Creates a new easily changable message video builder
    ///
    /// # Example
    /// ```
    /// let message =
    /// teloxide_tests::MockMessageVideo::new().video(teloxide_tests::MockVideo::new().file_id("12345".into()).build()).build();
    /// assert_eq!(message.video().unwrap().file.id, "12345".into());
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            None,
            vec![],
            None,
            Self::SHOW_CAPTION_ABOVE_MEDIA,
            Self::HAS_MEDIA_SPOILER,
            MockVideo::new().build(),
        )
    }

    /// Builds the message video
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageVideo::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.video().unwrap().file.id, teloxide_tests::MockVideo::FILE_ID.into()); // FILE_ID is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Video(MediaVideo {
                caption: self.caption,
                caption_entities: self.caption_entities,
                media_group_id: self.media_group_id,
                show_caption_above_media: self.show_caption_above_media,
                has_media_spoiler: self.has_media_spoiler,
                video: self.video,
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageVideoNote {
        pub length: u32,
        pub duration: Seconds,
        pub thumbnail: Option<PhotoSize>,
        // File meta
        pub file_id: FileId,
        pub file_unique_id: FileUniqueId,
        pub file_size: u32,
    }
}

impl MockMessageVideoNote {
    pub const LENGTH: u32 = 50;
    pub const DURATION: Seconds = Seconds::from_seconds(50);
    pub const FILE_ID: &'static str = "file_id";
    pub const FILE_UNIQUE_ID: &'static str = "file_unique_id";
    pub const FILE_SIZE: u32 = 50;

    /// Creates a new easily changable message video note builder
    ///
    /// # Example
    /// ```
    /// let message = teloxide_tests::MockMessageVideoNote::new().length(50).build();
    /// assert_eq!(message.video_note().unwrap().length, 50);
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            Self::LENGTH,
            Self::DURATION,
            None,
            Self::FILE_ID.into(),
            Self::FILE_UNIQUE_ID.into(),
            Self::FILE_SIZE,
        )
    }

    /// Builds the message video note
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageVideoNote::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.video_note().unwrap().file.id, teloxide_tests::MockMessageVideoNote::FILE_ID.into());  // FILE_ID is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::VideoNote(MediaVideoNote {
                video_note: VideoNote {
                    file: FileMeta {
                        id: self.file_id,
                        unique_id: self.file_unique_id,
                        size: self.file_size,
                    },
                    length: self.length,
                    duration: self.duration,
                    thumbnail: self.thumbnail,
                },
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageVoice {
        pub duration: Seconds,
        pub mime_type: Option<Mime>,
        pub caption: Option<String>,
        pub caption_entities: Vec<MessageEntity>,
        // File meta
        pub file_id: FileId,
        pub file_unique_id: FileUniqueId,
        pub file_size: u32,
    }
}

impl MockMessageVoice {
    pub const DURATION: Seconds = Seconds::from_seconds(1);
    pub const FILE_ID: &'static str = "AwADawAgADADy_JxS2gopIVIIxlhAg";
    pub const FILE_UNIQUE_ID: &'static str = "file_unique_id";
    pub const FILE_SIZE: u32 = 4321;

    /// Creates a new easily changable message voice builder
    ///
    /// # Example
    /// ```
    /// use teloxide::types::Seconds;
    /// let message = teloxide_tests::MockMessageVoice::new().duration(Seconds::from_seconds(1)).build();
    /// assert_eq!(message.voice().unwrap().duration, Seconds::from_seconds(1));
    /// ```
    ///
    pub fn new() -> Self {
        Self::new_message_common(
            Self::DURATION,
            None,
            None,
            vec![],
            Self::FILE_ID.into(),
            Self::FILE_UNIQUE_ID.into(),
            Self::FILE_SIZE,
        )
    }

    /// Builds the message voice
    ///
    /// # Example
    /// ```
    /// let mock_message = teloxide_tests::MockMessageVoice::new();
    /// let message = mock_message.build();
    /// assert_eq!(message.voice().unwrap().file.id, teloxide_tests::MockMessageVoice::FILE_ID.into());  // FILE_ID is a default value
    /// ```
    ///
    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Voice(MediaVoice {
                voice: Voice {
                    file: FileMeta {
                        id: self.file_id,
                        unique_id: self.file_unique_id,
                        size: self.file_size,
                    },
                    duration: self.duration,
                    mime_type: self.mime_type,
                },
                caption: self.caption,
                caption_entities: self.caption_entities,
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageMigrationFromChat {
        pub migrate_from_chat_id: i64,
    }
}

impl MockMessageMigrationFromChat {
    pub const MIGRATE_FROM_CHAT_ID: i64 = 1;

    pub fn new() -> Self {
        Self::new_message_common(Self::MIGRATE_FROM_CHAT_ID)
    }

    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Migration(ChatMigration::From {
                chat_id: ChatId(self.migrate_from_chat_id),
            }))
    }
}

MessageCommon! {
    #[derive(Changeable, Clone)]
    pub struct MockMessageMigrationToChat {
        pub migrate_to_chat_id: i64,
    }
}

impl MockMessageMigrationToChat {
    pub const MIGRATE_TO_CHAT_ID: i64 = 1;

    pub fn new() -> Self {
        Self::new_message_common(Self::MIGRATE_TO_CHAT_ID)
    }

    pub fn build(self) -> Message {
        self.clone()
            .build_message_common(MediaKind::Migration(ChatMigration::To {
                chat_id: ChatId(self.migrate_to_chat_id),
            }))
    }
}