open-lark 0.14.0

Enterprise-grade Lark/Feishu Open API SDK with comprehensive Chinese documentation and advanced error handling
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
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};

/// 消息类型枚举
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MessageType {
    /// 文本消息
    Text,
    /// 富文本消息
    Post,
    /// 图片消息
    Image,
    /// 文件消息
    File,
    /// 音频消息
    Audio,
    /// 视频消息
    Media,
    /// 表情包消息
    Sticker,
    /// 交互式消息卡片
    Interactive,
    /// 分享群名片
    ShareChat,
    /// 分享用户名片
    ShareUser,
    /// 系统消息
    System,
}

/// 用户ID类型
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum UserIdType {
    UserId,
    UnionId,
    OpenId,
}

impl UserIdType {
    pub fn as_str(&self) -> &'static str {
        match self {
            UserIdType::UserId => "user_id",
            UserIdType::UnionId => "union_id",
            UserIdType::OpenId => "open_id",
        }
    }
}

/// 接收ID类型
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ReceiveIdType {
    OpenId,
    UserId,
    UnionId,
    Email,
    ChatId,
}

impl ReceiveIdType {
    pub fn as_str(&self) -> &'static str {
        match self {
            ReceiveIdType::OpenId => "open_id",
            ReceiveIdType::UserId => "user_id",
            ReceiveIdType::UnionId => "union_id",
            ReceiveIdType::Email => "email",
            ReceiveIdType::ChatId => "chat_id",
        }
    }
}

/// 批量消息状态
#[derive(Debug, Clone, PartialEq, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum BatchMessageStatus {
    /// 处理中
    Processing = 0,
    /// 部分成功
    PartialSuccess = 1,
    /// 全部成功
    Success = 2,
    /// 全部失败
    Failed = 3,
}

/// 表情回复类型
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EmojiType {
    /// 表情类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub emoji_type: Option<String>,
}

impl EmojiType {
    pub fn new() -> Self {
        Self { emoji_type: None }
    }

    pub fn with_emoji_type(mut self, emoji_type: impl Into<String>) -> Self {
        self.emoji_type = Some(emoji_type.into());
        self
    }
}

impl Default for EmojiType {
    fn default() -> Self {
        Self::new()
    }
}

/// 表情回复信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MessageReaction {
    /// 消息ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message_id: Option<String>,
    /// 表情类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub emoji_type: Option<EmojiType>,
    /// 回复次数
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reaction_count: Option<i32>,
    /// 是否包含当前用户
    #[serde(skip_serializing_if = "Option::is_none")]
    pub has_reacted: Option<bool>,
    /// 回复用户列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reaction_users: Option<Vec<ReactionUser>>,
}

/// 表情回复用户信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ReactionUser {
    /// 用户ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_id: Option<String>,
    /// 用户名称
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// 用户头像
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar: Option<String>,
    /// 回复时间
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reaction_time: Option<String>,
}

/// Pin消息信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Pin {
    /// Pin ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pin_id: Option<String>,
    /// 消息ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message_id: Option<String>,
    /// 聊天ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub chat_id: Option<String>,
    /// Pin创建者
    #[serde(skip_serializing_if = "Option::is_none")]
    pub operator_id: Option<String>,
    /// Pin类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pin_type: Option<String>,
    /// 创建时间
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create_time: Option<String>,
}

/// 批量消息信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct BatchMessage {
    /// 批量消息ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub batch_message_id: Option<String>,
    /// 消息ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message_id: Option<String>,
    /// 状态
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<BatchMessageStatus>,
    /// 已发送人数
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sent_count: Option<i32>,
    /// 已读人数
    #[serde(skip_serializing_if = "Option::is_none")]
    pub read_count: Option<i32>,
    /// 总人数
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total_count: Option<i32>,
    /// 发送进度
    #[serde(skip_serializing_if = "Option::is_none")]
    pub progress: Option<f64>,
}

/// 图片信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ImageInfo {
    /// 图片key
    #[serde(skip_serializing_if = "Option::is_none")]
    pub image_key: Option<String>,
    /// 图片类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub image_type: Option<String>,
    /// 图片大小
    #[serde(skip_serializing_if = "Option::is_none")]
    pub image_size: Option<i64>,
    /// 图片宽度
    #[serde(skip_serializing_if = "Option::is_none")]
    pub width: Option<i32>,
    /// 图片高度
    #[serde(skip_serializing_if = "Option::is_none")]
    pub height: Option<i32>,
}

/// 文件信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FileInfo {
    /// 文件key
    #[serde(skip_serializing_if = "Option::is_none")]
    pub file_key: Option<String>,
    /// 文件名
    #[serde(skip_serializing_if = "Option::is_none")]
    pub file_name: Option<String>,
    /// 文件类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub file_type: Option<String>,
    /// 文件大小
    #[serde(skip_serializing_if = "Option::is_none")]
    pub file_size: Option<i64>,
    /// 文件token
    #[serde(skip_serializing_if = "Option::is_none")]
    pub file_token: Option<String>,
}

/// 消息卡片信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MessageCard {
    /// 卡片ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub card_id: Option<String>,
    /// 卡片内容
    #[serde(skip_serializing_if = "Option::is_none")]
    pub card: Option<serde_json::Value>,
    /// 是否仅特定人可见
    #[serde(skip_serializing_if = "Option::is_none")]
    pub update_multi: Option<bool>,
    /// 特定用户列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_id_list: Option<Vec<String>>,
}

/// 加急类型
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum UrgentType {
    /// 应用内加急
    App,
    /// 短信加急
    Sms,
    /// 电话加急
    Phone,
}

/// 加急信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UrgentInfo {
    /// 加急类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub urgent_type: Option<UrgentType>,
    /// 加急用户列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_id_list: Option<Vec<String>>,
    /// 自定义消息内容
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,
}

/// URL预览信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UrlPreview {
    /// URL
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    /// 标题
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,
    /// 描述
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// 图片URL
    #[serde(skip_serializing_if = "Option::is_none")]
    pub image_url: Option<String>,
    /// 预览类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub preview_type: Option<String>,
}

/// 分页信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PageInfo {
    /// 分页标记
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_token: Option<String>,
    /// 是否还有更多页
    #[serde(skip_serializing_if = "Option::is_none")]
    pub has_more: Option<bool>,
}

/// 消息已读信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct MessageReadInfo {
    /// 已读用户列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub read_users: Option<Vec<ReadUser>>,
    /// 是否还有更多
    #[serde(skip_serializing_if = "Option::is_none")]
    pub has_more: Option<bool>,
    /// 分页标记
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_token: Option<String>,
}

/// 已读用户信息
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ReadUser {
    /// 用户ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_id: Option<String>,
    /// 已读时间
    #[serde(skip_serializing_if = "Option::is_none")]
    pub read_time: Option<String>,
    /// 租户key
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tenant_key: Option<String>,
}

#[cfg(test)]
#[allow(unused_variables, unused_unsafe)]
mod tests {
    use super::*;

    #[test]
    fn test_message_type_serialization() {
        let types = vec![
            MessageType::Text,
            MessageType::Post,
            MessageType::Image,
            MessageType::File,
            MessageType::Audio,
            MessageType::Media,
            MessageType::Sticker,
            MessageType::Interactive,
            MessageType::ShareChat,
            MessageType::ShareUser,
            MessageType::System,
        ];

        for msg_type in types {
            let serialized = serde_json::to_string(&msg_type).unwrap();
            let deserialized: MessageType = serde_json::from_str(&serialized).unwrap();
            assert_eq!(msg_type, deserialized);
        }
    }

    #[test]
    fn test_user_id_type_serialization() {
        let types = vec![UserIdType::UserId, UserIdType::UnionId, UserIdType::OpenId];

        for user_type in types {
            let serialized = serde_json::to_string(&user_type).unwrap();
            let deserialized: UserIdType = serde_json::from_str(&serialized).unwrap();
            assert_eq!(user_type, deserialized);
        }
    }

    #[test]
    fn test_user_id_type_as_str() {
        assert_eq!(UserIdType::UserId.as_str(), "user_id");
        assert_eq!(UserIdType::UnionId.as_str(), "union_id");
        assert_eq!(UserIdType::OpenId.as_str(), "open_id");
    }

    #[test]
    fn test_receive_id_type_serialization() {
        let types = vec![
            ReceiveIdType::OpenId,
            ReceiveIdType::UserId,
            ReceiveIdType::UnionId,
            ReceiveIdType::Email,
            ReceiveIdType::ChatId,
        ];

        for receive_type in types {
            let serialized = serde_json::to_string(&receive_type).unwrap();
            let deserialized: ReceiveIdType = serde_json::from_str(&serialized).unwrap();
            assert_eq!(receive_type, deserialized);
        }
    }

    #[test]
    fn test_receive_id_type_as_str() {
        assert_eq!(ReceiveIdType::OpenId.as_str(), "open_id");
        assert_eq!(ReceiveIdType::UserId.as_str(), "user_id");
        assert_eq!(ReceiveIdType::UnionId.as_str(), "union_id");
        assert_eq!(ReceiveIdType::Email.as_str(), "email");
        assert_eq!(ReceiveIdType::ChatId.as_str(), "chat_id");
    }

    #[test]
    fn test_batch_message_status_serialization() {
        let statuses = vec![
            BatchMessageStatus::Processing,
            BatchMessageStatus::PartialSuccess,
            BatchMessageStatus::Success,
            BatchMessageStatus::Failed,
        ];

        for status in statuses {
            let serialized = serde_json::to_string(&status).unwrap();
            let deserialized: BatchMessageStatus = serde_json::from_str(&serialized).unwrap();
            assert_eq!(status, deserialized);
        }
    }

    #[test]
    fn test_batch_message_status_values() {
        assert_eq!(BatchMessageStatus::Processing as u8, 0);
        assert_eq!(BatchMessageStatus::PartialSuccess as u8, 1);
        assert_eq!(BatchMessageStatus::Success as u8, 2);
        assert_eq!(BatchMessageStatus::Failed as u8, 3);
    }

    #[test]
    fn test_emoji_type_creation() {
        let emoji = EmojiType::new();
        assert_eq!(emoji.emoji_type, None);

        let emoji_with_type = EmojiType::new().with_emoji_type("smile");
        assert_eq!(emoji_with_type.emoji_type, Some("smile".to_string()));
    }

    #[test]
    fn test_emoji_type_default() {
        let emoji: EmojiType = Default::default();
        assert_eq!(emoji.emoji_type, None);
    }

    #[test]
    fn test_emoji_type_serialization() {
        let emoji = EmojiType {
            emoji_type: Some("thumbs_up".to_string()),
        };

        let serialized = serde_json::to_string(&emoji).unwrap();
        let deserialized: EmojiType = serde_json::from_str(&serialized).unwrap();

        assert_eq!(emoji.emoji_type, deserialized.emoji_type);
    }

    #[test]
    fn test_message_reaction_serialization() {
        let reaction = MessageReaction {
            message_id: Some("msg_123".to_string()),
            emoji_type: Some(EmojiType {
                emoji_type: Some("heart".to_string()),
            }),
            reaction_count: Some(5),
            has_reacted: Some(true),
            reaction_users: Some(vec![ReactionUser {
                user_id: Some("user_456".to_string()),
                name: Some("张三".to_string()),
                avatar: Some("avatar_url".to_string()),
                reaction_time: Some("2024-01-01T10:00:00Z".to_string()),
            }]),
        };

        let serialized = serde_json::to_string(&reaction).unwrap();
        let deserialized: MessageReaction = serde_json::from_str(&serialized).unwrap();

        assert_eq!(reaction.message_id, deserialized.message_id);
        assert_eq!(reaction.reaction_count, deserialized.reaction_count);
        assert_eq!(reaction.has_reacted, deserialized.has_reacted);
        assert_eq!(
            reaction.reaction_users.as_ref().unwrap().len(),
            deserialized.reaction_users.as_ref().unwrap().len()
        );
    }

    #[test]
    fn test_reaction_user_serialization() {
        let user = ReactionUser {
            user_id: Some("user_789".to_string()),
            name: Some("李四".to_string()),
            avatar: Some("https://avatar.example.com/789".to_string()),
            reaction_time: Some("2024-01-01T11:30:00Z".to_string()),
        };

        let serialized = serde_json::to_string(&user).unwrap();
        let deserialized: ReactionUser = serde_json::from_str(&serialized).unwrap();

        assert_eq!(user.user_id, deserialized.user_id);
        assert_eq!(user.name, deserialized.name);
        assert_eq!(user.avatar, deserialized.avatar);
        assert_eq!(user.reaction_time, deserialized.reaction_time);
    }

    #[test]
    fn test_pin_serialization() {
        let pin = Pin {
            pin_id: Some("pin_123".to_string()),
            message_id: Some("msg_456".to_string()),
            chat_id: Some("chat_789".to_string()),
            operator_id: Some("operator_101".to_string()),
            pin_type: Some("manual".to_string()),
            create_time: Some("2024-01-01T09:00:00Z".to_string()),
        };

        let serialized = serde_json::to_string(&pin).unwrap();
        let deserialized: Pin = serde_json::from_str(&serialized).unwrap();

        assert_eq!(pin.pin_id, deserialized.pin_id);
        assert_eq!(pin.message_id, deserialized.message_id);
        assert_eq!(pin.chat_id, deserialized.chat_id);
        assert_eq!(pin.operator_id, deserialized.operator_id);
        assert_eq!(pin.pin_type, deserialized.pin_type);
        assert_eq!(pin.create_time, deserialized.create_time);
    }

    #[test]
    fn test_batch_message_serialization() {
        let batch_msg = BatchMessage {
            batch_message_id: Some("batch_123".to_string()),
            message_id: Some("msg_456".to_string()),
            status: Some(BatchMessageStatus::PartialSuccess),
            sent_count: Some(80),
            read_count: Some(65),
            total_count: Some(100),
            progress: Some(0.8),
        };

        let serialized = serde_json::to_string(&batch_msg).unwrap();
        let deserialized: BatchMessage = serde_json::from_str(&serialized).unwrap();

        assert_eq!(batch_msg.batch_message_id, deserialized.batch_message_id);
        assert_eq!(batch_msg.message_id, deserialized.message_id);
        assert_eq!(batch_msg.status, deserialized.status);
        assert_eq!(batch_msg.sent_count, deserialized.sent_count);
        assert_eq!(batch_msg.read_count, deserialized.read_count);
        assert_eq!(batch_msg.total_count, deserialized.total_count);
        assert_eq!(batch_msg.progress, deserialized.progress);
    }

    #[test]
    fn test_image_info_serialization() {
        let image = ImageInfo {
            image_key: Some("img_key_123".to_string()),
            image_type: Some("png".to_string()),
            image_size: Some(1024000),
            width: Some(1920),
            height: Some(1080),
        };

        let serialized = serde_json::to_string(&image).unwrap();
        let deserialized: ImageInfo = serde_json::from_str(&serialized).unwrap();

        assert_eq!(image.image_key, deserialized.image_key);
        assert_eq!(image.image_type, deserialized.image_type);
        assert_eq!(image.image_size, deserialized.image_size);
        assert_eq!(image.width, deserialized.width);
        assert_eq!(image.height, deserialized.height);
    }

    #[test]
    fn test_file_info_serialization() {
        let file = FileInfo {
            file_key: Some("file_key_456".to_string()),
            file_name: Some("document.pdf".to_string()),
            file_type: Some("pdf".to_string()),
            file_size: Some(2048000),
            file_token: Some("token_789".to_string()),
        };

        let serialized = serde_json::to_string(&file).unwrap();
        let deserialized: FileInfo = serde_json::from_str(&serialized).unwrap();

        assert_eq!(file.file_key, deserialized.file_key);
        assert_eq!(file.file_name, deserialized.file_name);
        assert_eq!(file.file_type, deserialized.file_type);
        assert_eq!(file.file_size, deserialized.file_size);
        assert_eq!(file.file_token, deserialized.file_token);
    }

    #[test]
    fn test_message_card_serialization() {
        let card_content = serde_json::json!({
            "type": "template",
            "data": {
                "template_id": "ctp_123",
                "template_variable": {
                    "title": "测试卡片",
                    "content": "这是一个测试消息卡片"
                }
            }
        });

        let card = MessageCard {
            card_id: Some("card_123".to_string()),
            card: Some(card_content.clone()),
            update_multi: Some(false),
            user_id_list: Some(vec!["user_1".to_string(), "user_2".to_string()]),
        };

        let serialized = serde_json::to_string(&card).unwrap();
        let deserialized: MessageCard = serde_json::from_str(&serialized).unwrap();

        assert_eq!(card.card_id, deserialized.card_id);
        assert_eq!(card.update_multi, deserialized.update_multi);
        assert_eq!(card.user_id_list, deserialized.user_id_list);
        assert!(deserialized.card.is_some());
    }

    #[test]
    fn test_urgent_type_serialization() {
        let types = vec![UrgentType::App, UrgentType::Sms, UrgentType::Phone];

        for urgent_type in types {
            let serialized = serde_json::to_string(&urgent_type).unwrap();
            let deserialized: UrgentType = serde_json::from_str(&serialized).unwrap();
            assert_eq!(urgent_type, deserialized);
        }
    }

    #[test]
    fn test_urgent_info_serialization() {
        let urgent = UrgentInfo {
            urgent_type: Some(UrgentType::Sms),
            user_id_list: Some(vec![
                "urgent_user_1".to_string(),
                "urgent_user_2".to_string(),
            ]),
            message: Some("紧急通知:请立即处理".to_string()),
        };

        let serialized = serde_json::to_string(&urgent).unwrap();
        let deserialized: UrgentInfo = serde_json::from_str(&serialized).unwrap();

        assert_eq!(urgent.urgent_type, deserialized.urgent_type);
        assert_eq!(urgent.user_id_list, deserialized.user_id_list);
        assert_eq!(urgent.message, deserialized.message);
    }

    #[test]
    fn test_url_preview_serialization() {
        let preview = UrlPreview {
            url: Some("https://example.com".to_string()),
            title: Some("示例网站".to_string()),
            description: Some("这是一个示例网站的描述".to_string()),
            image_url: Some("https://example.com/image.jpg".to_string()),
            preview_type: Some("link".to_string()),
        };

        let serialized = serde_json::to_string(&preview).unwrap();
        let deserialized: UrlPreview = serde_json::from_str(&serialized).unwrap();

        assert_eq!(preview.url, deserialized.url);
        assert_eq!(preview.title, deserialized.title);
        assert_eq!(preview.description, deserialized.description);
        assert_eq!(preview.image_url, deserialized.image_url);
        assert_eq!(preview.preview_type, deserialized.preview_type);
    }

    #[test]
    fn test_page_info_serialization() {
        let page_info = PageInfo {
            page_token: Some("token_next_page".to_string()),
            has_more: Some(true),
        };

        let serialized = serde_json::to_string(&page_info).unwrap();
        let deserialized: PageInfo = serde_json::from_str(&serialized).unwrap();

        assert_eq!(page_info.page_token, deserialized.page_token);
        assert_eq!(page_info.has_more, deserialized.has_more);
    }

    #[test]
    fn test_message_read_info_serialization() {
        let read_info = MessageReadInfo {
            read_users: Some(vec![
                ReadUser {
                    user_id: Some("reader_1".to_string()),
                    read_time: Some("2024-01-01T10:15:00Z".to_string()),
                    tenant_key: Some("tenant_a".to_string()),
                },
                ReadUser {
                    user_id: Some("reader_2".to_string()),
                    read_time: Some("2024-01-01T10:20:00Z".to_string()),
                    tenant_key: Some("tenant_b".to_string()),
                },
            ]),
            has_more: Some(false),
            page_token: Some("end_token".to_string()),
        };

        let serialized = serde_json::to_string(&read_info).unwrap();
        let deserialized: MessageReadInfo = serde_json::from_str(&serialized).unwrap();

        assert_eq!(read_info.has_more, deserialized.has_more);
        assert_eq!(read_info.page_token, deserialized.page_token);
        assert_eq!(
            read_info.read_users.as_ref().unwrap().len(),
            deserialized.read_users.as_ref().unwrap().len()
        );
    }

    #[test]
    fn test_read_user_serialization() {
        let read_user = ReadUser {
            user_id: Some("reader_123".to_string()),
            read_time: Some("2024-01-01T14:30:00Z".to_string()),
            tenant_key: Some("tenant_xyz".to_string()),
        };

        let serialized = serde_json::to_string(&read_user).unwrap();
        let deserialized: ReadUser = serde_json::from_str(&serialized).unwrap();

        assert_eq!(read_user.user_id, deserialized.user_id);
        assert_eq!(read_user.read_time, deserialized.read_time);
        assert_eq!(read_user.tenant_key, deserialized.tenant_key);
    }

    #[test]
    fn test_models_with_none_values() {
        let emoji = EmojiType { emoji_type: None };
        let serialized = serde_json::to_string(&emoji).unwrap();
        let deserialized: EmojiType = serde_json::from_str(&serialized).unwrap();
        assert_eq!(emoji.emoji_type, deserialized.emoji_type);

        let reaction = MessageReaction {
            message_id: None,
            emoji_type: None,
            reaction_count: None,
            has_reacted: None,
            reaction_users: None,
        };
        let serialized = serde_json::to_string(&reaction).unwrap();
        let deserialized: MessageReaction = serde_json::from_str(&serialized).unwrap();
        assert!(deserialized.message_id.is_none());
        assert!(deserialized.emoji_type.is_none());
        assert!(deserialized.reaction_count.is_none());
    }

    #[test]
    fn test_complex_message_reaction_with_multiple_users() {
        let reaction = MessageReaction {
            message_id: Some("complex_msg_123".to_string()),
            emoji_type: Some(EmojiType {
                emoji_type: Some("party".to_string()),
            }),
            reaction_count: Some(3),
            has_reacted: Some(true),
            reaction_users: Some(vec![
                ReactionUser {
                    user_id: Some("user_a".to_string()),
                    name: Some("用户A".to_string()),
                    avatar: Some("avatar_a.jpg".to_string()),
                    reaction_time: Some("2024-01-01T09:00:00Z".to_string()),
                },
                ReactionUser {
                    user_id: Some("user_b".to_string()),
                    name: Some("用户B".to_string()),
                    avatar: Some("avatar_b.jpg".to_string()),
                    reaction_time: Some("2024-01-01T09:05:00Z".to_string()),
                },
                ReactionUser {
                    user_id: Some("user_c".to_string()),
                    name: Some("用户C".to_string()),
                    avatar: Some("avatar_c.jpg".to_string()),
                    reaction_time: Some("2024-01-01T09:10:00Z".to_string()),
                },
            ]),
        };

        let serialized = serde_json::to_string(&reaction).unwrap();
        let deserialized: MessageReaction = serde_json::from_str(&serialized).unwrap();

        assert_eq!(reaction.message_id, deserialized.message_id);
        assert_eq!(reaction.reaction_count, deserialized.reaction_count);
        assert_eq!(reaction.has_reacted, deserialized.has_reacted);
        assert_eq!(reaction.reaction_users.as_ref().unwrap().len(), 3);
        assert_eq!(deserialized.reaction_users.as_ref().unwrap().len(), 3);

        let first_user = &reaction.reaction_users.as_ref().unwrap()[0];
        let deserialized_first_user = &deserialized.reaction_users.as_ref().unwrap()[0];
        assert_eq!(first_user.user_id, deserialized_first_user.user_id);
        assert_eq!(first_user.name, deserialized_first_user.name);
    }

    #[test]
    fn test_debug_trait_for_models() {
        let msg_type = MessageType::Interactive;
        let debug_string = format!("{:?}", msg_type);
        assert!(debug_string.contains("Interactive"));

        let user_type = UserIdType::OpenId;
        let debug_string = format!("{:?}", user_type);
        assert!(debug_string.contains("OpenId"));

        let batch_status = BatchMessageStatus::Success;
        let debug_string = format!("{:?}", batch_status);
        assert!(debug_string.contains("Success"));
    }
}