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
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
use serde::{Deserialize, Serialize};

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

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

/// 部门ID类型
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DepartmentIdType {
    #[serde(rename = "open_department_id")]
    OpenDepartmentId,
    #[serde(rename = "department_id")]
    DepartmentId,
}

impl DepartmentIdType {
    pub fn as_str(&self) -> &str {
        match self {
            DepartmentIdType::OpenDepartmentId => "open_department_id",
            DepartmentIdType::DepartmentId => "department_id",
        }
    }
}

/// 应用信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Application {
    /// 应用ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub app_id: Option<String>,
    /// 应用名称
    #[serde(skip_serializing_if = "Option::is_none")]
    pub app_name: Option<String>,
    /// 应用描述
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// 应用图标
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar_url: Option<String>,
    /// 应用类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub app_type: Option<AppType>,
    /// 应用状态
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<AppStatus>,
    /// 创建时间
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create_time: Option<String>,
    /// 更新时间
    #[serde(skip_serializing_if = "Option::is_none")]
    pub update_time: Option<String>,
}

/// 应用类型
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AppType {
    /// 自建应用
    #[serde(rename = "self_built")]
    SelfBuilt,
    /// 应用商店应用
    #[serde(rename = "marketplace")]
    Marketplace,
}

/// 应用状态
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AppStatus {
    /// 开发中
    #[serde(rename = "developing")]
    Developing,
    /// 已发布
    #[serde(rename = "published")]
    Published,
    /// 已下架
    #[serde(rename = "removed")]
    Removed,
    /// 已停用
    #[serde(rename = "disabled")]
    Disabled,
}

/// 应用版本信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppVersion {
    /// 版本ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version_id: Option<String>,
    /// 版本号
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,
    /// 版本名称
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version_name: Option<String>,
    /// 版本描述
    #[serde(skip_serializing_if = "Option::is_none")]
    pub remark: Option<String>,
    /// 创建时间
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create_time: Option<String>,
    /// 发布时间
    #[serde(skip_serializing_if = "Option::is_none")]
    pub publish_time: Option<String>,
    /// 版本状态
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<VersionStatus>,
}

/// 版本状态
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum VersionStatus {
    /// 开发中
    #[serde(rename = "developing")]
    Developing,
    /// 审核中
    #[serde(rename = "auditing")]
    Auditing,
    /// 已发布
    #[serde(rename = "published")]
    Published,
    /// 审核拒绝
    #[serde(rename = "rejected")]
    Rejected,
}

/// 应用协作者
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppCollaborator {
    /// 协作者ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub collaborator_id: Option<String>,
    /// 协作者类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub collaborator_type: Option<CollaboratorType>,
    /// 权限
    #[serde(skip_serializing_if = "Option::is_none")]
    pub permissions: Option<Vec<String>>,
}

/// 协作者类型
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CollaboratorType {
    /// 用户
    #[serde(rename = "user")]
    User,
    /// 群组
    #[serde(rename = "group")]
    Group,
}

/// 权限范围
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PermissionScope {
    /// 权限
    #[serde(skip_serializing_if = "Option::is_none")]
    pub permission: Option<String>,
    /// 是否已授权
    #[serde(skip_serializing_if = "Option::is_none")]
    pub granted: Option<bool>,
    /// 授权状态
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<AuthStatus>,
}

/// 授权状态
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AuthStatus {
    /// 已授权
    #[serde(rename = "granted")]
    Granted,
    /// 未授权
    #[serde(rename = "not_granted")]
    NotGranted,
    /// 审核中
    #[serde(rename = "pending")]
    Pending,
    /// 已拒绝
    #[serde(rename = "rejected")]
    Rejected,
}

/// 应用管理员
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppAdmin {
    /// 用户ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_id: Option<String>,
    /// 管理权限
    #[serde(skip_serializing_if = "Option::is_none")]
    pub permissions: Option<Vec<AdminPermission>>,
}

/// 管理员权限
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AdminPermission {
    /// 应用管理
    #[serde(rename = "app_management")]
    AppManagement,
    /// 用户管理
    #[serde(rename = "user_management")]
    UserManagement,
    /// 权限管理
    #[serde(rename = "permission_management")]
    PermissionManagement,
}

/// 应用可用范围
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppAvailability {
    /// 是否对所有人可用
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_visible_to_all: Option<bool>,
    /// 白名单用户
    #[serde(skip_serializing_if = "Option::is_none")]
    pub visible_list: Option<VisibilityList>,
    /// 黑名单用户
    #[serde(skip_serializing_if = "Option::is_none")]
    pub invisible_list: Option<VisibilityList>,
}

/// 可见性列表
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VisibilityList {
    /// 用户列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_list: Option<Vec<String>>,
    /// 部门列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub department_list: Option<Vec<String>>,
    /// 用户组列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub group_list: Option<Vec<String>>,
}

/// 应用使用统计
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppUsage {
    /// 日期
    #[serde(skip_serializing_if = "Option::is_none")]
    pub date: Option<String>,
    /// 活跃用户数
    #[serde(skip_serializing_if = "Option::is_none")]
    pub active_users: Option<i64>,
    /// 新增用户数
    #[serde(skip_serializing_if = "Option::is_none")]
    pub new_users: Option<i64>,
    /// 消息推送数
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message_push_count: Option<i64>,
}

/// 部门使用统计
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DepartmentUsage {
    /// 部门ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub department_id: Option<String>,
    /// 部门名称
    #[serde(skip_serializing_if = "Option::is_none")]
    pub department_name: Option<String>,
    /// 活跃用户数
    #[serde(skip_serializing_if = "Option::is_none")]
    pub active_users: Option<i64>,
    /// 总用户数
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total_users: Option<i64>,
}

/// 应用反馈
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppFeedback {
    /// 反馈ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub feedback_id: Option<String>,
    /// 用户ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_id: Option<String>,
    /// 反馈类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub feedback_type: Option<FeedbackType>,
    /// 反馈内容
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<String>,
    /// 评分
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rating: Option<i32>,
    /// 创建时间
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create_time: Option<String>,
    /// 状态
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<FeedbackStatus>,
}

/// 反馈类型
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FeedbackType {
    /// 问题反馈
    #[serde(rename = "bug")]
    Bug,
    /// 功能建议
    #[serde(rename = "feature")]
    Feature,
    /// 其他
    #[serde(rename = "other")]
    Other,
}

/// 反馈状态
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FeedbackStatus {
    /// 待处理
    #[serde(rename = "pending")]
    Pending,
    /// 处理中
    #[serde(rename = "processing")]
    Processing,
    /// 已完成
    #[serde(rename = "completed")]
    Completed,
    /// 已关闭
    #[serde(rename = "closed")]
    Closed,
}

/// 应用红点设置
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppBadge {
    /// 红点类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub badge_type: Option<BadgeType>,
    /// 红点内容
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<String>,
}

/// 红点类型
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum BadgeType {
    /// 数字红点
    #[serde(rename = "number")]
    Number,
    /// 圆点红点
    #[serde(rename = "dot")]
    Dot,
    /// 清除红点
    #[serde(rename = "clear")]
    Clear,
}

/// 付费订单信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Order {
    /// 订单ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order_id: Option<String>,
    /// 订单状态
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<OrderStatus>,
    /// 付费方案ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pricing_plan_id: Option<String>,
    /// 购买数量
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quantity: Option<i64>,
    /// 购买时间
    #[serde(skip_serializing_if = "Option::is_none")]
    pub purchase_time: Option<String>,
    /// 到期时间
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expire_time: Option<String>,
}

/// 订单状态
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum OrderStatus {
    /// 待支付
    #[serde(rename = "pending")]
    Pending,
    /// 已支付
    #[serde(rename = "paid")]
    Paid,
    /// 已取消
    #[serde(rename = "cancelled")]
    Cancelled,
    /// 已过期
    #[serde(rename = "expired")]
    Expired,
}

/// 付费方案
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PricingPlan {
    /// 方案ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pricing_plan_id: Option<String>,
    /// 方案名称
    #[serde(skip_serializing_if = "Option::is_none")]
    pub plan_name: Option<String>,
    /// 方案描述
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// 价格
    #[serde(skip_serializing_if = "Option::is_none")]
    pub price: Option<String>,
    /// 计费周期
    #[serde(skip_serializing_if = "Option::is_none")]
    pub billing_cycle: Option<BillingCycle>,
}

/// 计费周期
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum BillingCycle {
    /// 月付
    #[serde(rename = "monthly")]
    Monthly,
    /// 年付
    #[serde(rename = "yearly")]
    Yearly,
    /// 一次性
    #[serde(rename = "once")]
    Once,
}

/// 应用审核状态
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuditStatus {
    /// 审核状态
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<AuditResult>,
    /// 审核意见
    #[serde(skip_serializing_if = "Option::is_none")]
    pub comment: Option<String>,
    /// 审核时间
    #[serde(skip_serializing_if = "Option::is_none")]
    pub audit_time: Option<String>,
}

/// 审核结果
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AuditResult {
    /// 待审核
    #[serde(rename = "pending")]
    Pending,
    /// 审核通过
    #[serde(rename = "approved")]
    Approved,
    /// 审核拒绝
    #[serde(rename = "rejected")]
    Rejected,
}

/// 通讯录权限范围
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContactsRange {
    /// 权限范围类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub range_type: Option<ContactsRangeType>,
    /// 部门列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub department_list: Option<Vec<String>>,
    /// 用户列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_list: Option<Vec<String>>,
}

/// 通讯录权限范围类型
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ContactsRangeType {
    /// 全员
    #[serde(rename = "all")]
    All,
    /// 部分员工
    #[serde(rename = "some")]
    Some,
    /// 当前应用管理范围
    #[serde(rename = "admin_range")]
    AdminRange,
}

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

    #[test]
    fn test_user_id_type_enum() {
        assert_eq!(
            serde_json::to_string(&UserIdType::OpenId).unwrap(),
            "\"open_id\""
        );
        assert_eq!(
            serde_json::to_string(&UserIdType::UserId).unwrap(),
            "\"user_id\""
        );
        assert_eq!(
            serde_json::to_string(&UserIdType::UnionId).unwrap(),
            "\"union_id\""
        );
    }

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

    #[test]
    fn test_department_id_type_enum() {
        assert_eq!(
            serde_json::to_string(&DepartmentIdType::OpenDepartmentId).unwrap(),
            "\"open_department_id\""
        );
        assert_eq!(
            serde_json::to_string(&DepartmentIdType::DepartmentId).unwrap(),
            "\"department_id\""
        );
    }

    #[test]
    fn test_department_id_type_as_str() {
        assert_eq!(
            DepartmentIdType::OpenDepartmentId.as_str(),
            "open_department_id"
        );
        assert_eq!(DepartmentIdType::DepartmentId.as_str(), "department_id");
    }

    #[test]
    fn test_application_full() {
        let app = Application {
            app_id: Some("app123".to_string()),
            app_name: Some("测试应用".to_string()),
            description: Some("这是一个测试应用".to_string()),
            avatar_url: Some("https://example.com/avatar.png".to_string()),
            app_type: Some(AppType::SelfBuilt),
            status: Some(AppStatus::Published),
            create_time: Some("2024-01-01T00:00:00Z".to_string()),
            update_time: Some("2024-01-01T12:00:00Z".to_string()),
        };
        let json = serde_json::to_string(&app).unwrap();
        assert!(json.contains("app123"));
        assert!(json.contains("测试应用"));
        assert!(json.contains("self_built"));
        assert!(json.contains("published"));
    }

    #[test]
    fn test_app_type_enum() {
        assert_eq!(
            serde_json::to_string(&AppType::SelfBuilt).unwrap(),
            "\"self_built\""
        );
        assert_eq!(
            serde_json::to_string(&AppType::Marketplace).unwrap(),
            "\"marketplace\""
        );
    }

    #[test]
    fn test_app_status_enum() {
        assert_eq!(
            serde_json::to_string(&AppStatus::Developing).unwrap(),
            "\"developing\""
        );
        assert_eq!(
            serde_json::to_string(&AppStatus::Published).unwrap(),
            "\"published\""
        );
        assert_eq!(
            serde_json::to_string(&AppStatus::Removed).unwrap(),
            "\"removed\""
        );
        assert_eq!(
            serde_json::to_string(&AppStatus::Disabled).unwrap(),
            "\"disabled\""
        );
    }

    #[test]
    fn test_app_version() {
        let version = AppVersion {
            version_id: Some("v123".to_string()),
            version: Some("1.2.0".to_string()),
            version_name: Some("重要更新".to_string()),
            remark: Some("修复了若干bug".to_string()),
            create_time: Some("2024-01-01T00:00:00Z".to_string()),
            publish_time: Some("2024-01-02T00:00:00Z".to_string()),
            status: Some(VersionStatus::Published),
        };
        let json = serde_json::to_string(&version).unwrap();
        assert!(json.contains("v123"));
        assert!(json.contains("1.2.0"));
        assert!(json.contains("重要更新"));
        assert!(json.contains("published"));
    }

    #[test]
    fn test_version_status_enum() {
        assert_eq!(
            serde_json::to_string(&VersionStatus::Developing).unwrap(),
            "\"developing\""
        );
        assert_eq!(
            serde_json::to_string(&VersionStatus::Auditing).unwrap(),
            "\"auditing\""
        );
        assert_eq!(
            serde_json::to_string(&VersionStatus::Published).unwrap(),
            "\"published\""
        );
        assert_eq!(
            serde_json::to_string(&VersionStatus::Rejected).unwrap(),
            "\"rejected\""
        );
    }

    #[test]
    fn test_app_collaborator() {
        let collaborator = AppCollaborator {
            collaborator_id: Some("user123".to_string()),
            collaborator_type: Some(CollaboratorType::User),
            permissions: Some(vec!["read".to_string(), "write".to_string()]),
        };
        let json = serde_json::to_string(&collaborator).unwrap();
        assert!(json.contains("user123"));
        assert!(json.contains("user"));
        assert!(json.contains("read"));
    }

    #[test]
    fn test_collaborator_type_enum() {
        assert_eq!(
            serde_json::to_string(&CollaboratorType::User).unwrap(),
            "\"user\""
        );
        assert_eq!(
            serde_json::to_string(&CollaboratorType::Group).unwrap(),
            "\"group\""
        );
    }

    #[test]
    fn test_permission_scope() {
        let scope = PermissionScope {
            permission: Some("contacts:read".to_string()),
            granted: Some(true),
            status: Some(AuthStatus::Granted),
        };
        let json = serde_json::to_string(&scope).unwrap();
        assert!(json.contains("contacts:read"));
        assert!(json.contains("true"));
        assert!(json.contains("granted"));
    }

    #[test]
    fn test_auth_status_enum() {
        assert_eq!(
            serde_json::to_string(&AuthStatus::Granted).unwrap(),
            "\"granted\""
        );
        assert_eq!(
            serde_json::to_string(&AuthStatus::NotGranted).unwrap(),
            "\"not_granted\""
        );
        assert_eq!(
            serde_json::to_string(&AuthStatus::Pending).unwrap(),
            "\"pending\""
        );
        assert_eq!(
            serde_json::to_string(&AuthStatus::Rejected).unwrap(),
            "\"rejected\""
        );
    }

    #[test]
    fn test_app_admin() {
        let admin = AppAdmin {
            user_id: Some("admin123".to_string()),
            permissions: Some(vec![
                AdminPermission::AppManagement,
                AdminPermission::UserManagement,
            ]),
        };
        let json = serde_json::to_string(&admin).unwrap();
        assert!(json.contains("admin123"));
        assert!(json.contains("app_management"));
        assert!(json.contains("user_management"));
    }

    #[test]
    fn test_admin_permission_enum() {
        assert_eq!(
            serde_json::to_string(&AdminPermission::AppManagement).unwrap(),
            "\"app_management\""
        );
        assert_eq!(
            serde_json::to_string(&AdminPermission::UserManagement).unwrap(),
            "\"user_management\""
        );
        assert_eq!(
            serde_json::to_string(&AdminPermission::PermissionManagement).unwrap(),
            "\"permission_management\""
        );
    }

    #[test]
    fn test_app_availability() {
        let availability = AppAvailability {
            is_visible_to_all: Some(false),
            visible_list: Some(VisibilityList {
                user_list: Some(vec!["user1".to_string(), "user2".to_string()]),
                department_list: Some(vec!["dept1".to_string()]),
                group_list: Some(vec!["group1".to_string()]),
            }),
            invisible_list: None,
        };
        let json = serde_json::to_string(&availability).unwrap();
        assert!(json.contains("false"));
        assert!(json.contains("user1"));
        assert!(json.contains("dept1"));
    }

    #[test]
    fn test_visibility_list() {
        let list = VisibilityList {
            user_list: Some(vec!["user123".to_string()]),
            department_list: Some(vec!["tech".to_string(), "product".to_string()]),
            group_list: None,
        };
        let json = serde_json::to_string(&list).unwrap();
        assert!(json.contains("user123"));
        assert!(json.contains("tech"));
        assert!(json.contains("product"));
    }

    #[test]
    fn test_app_usage() {
        let usage = AppUsage {
            date: Some("2024-01-01".to_string()),
            active_users: Some(150),
            new_users: Some(20),
            message_push_count: Some(500),
        };
        let json = serde_json::to_string(&usage).unwrap();
        assert!(json.contains("2024-01-01"));
        assert!(json.contains("150"));
        assert!(json.contains("20"));
        assert!(json.contains("500"));
    }

    #[test]
    fn test_department_usage() {
        let usage = DepartmentUsage {
            department_id: Some("dept123".to_string()),
            department_name: Some("技术部".to_string()),
            active_users: Some(25),
            total_users: Some(30),
        };
        let json = serde_json::to_string(&usage).unwrap();
        assert!(json.contains("dept123"));
        assert!(json.contains("技术部"));
        assert!(json.contains("25"));
        assert!(json.contains("30"));
    }

    #[test]
    fn test_app_feedback() {
        let feedback = AppFeedback {
            feedback_id: Some("fb123".to_string()),
            user_id: Some("user456".to_string()),
            feedback_type: Some(FeedbackType::Bug),
            content: Some("应用启动很慢".to_string()),
            rating: Some(3),
            create_time: Some("2024-01-01T10:00:00Z".to_string()),
            status: Some(FeedbackStatus::Processing),
        };
        let json = serde_json::to_string(&feedback).unwrap();
        assert!(json.contains("fb123"));
        assert!(json.contains("bug"));
        assert!(json.contains("应用启动很慢"));
        assert!(json.contains("processing"));
    }

    #[test]
    fn test_feedback_type_enum() {
        assert_eq!(
            serde_json::to_string(&FeedbackType::Bug).unwrap(),
            "\"bug\""
        );
        assert_eq!(
            serde_json::to_string(&FeedbackType::Feature).unwrap(),
            "\"feature\""
        );
        assert_eq!(
            serde_json::to_string(&FeedbackType::Other).unwrap(),
            "\"other\""
        );
    }

    #[test]
    fn test_feedback_status_enum() {
        assert_eq!(
            serde_json::to_string(&FeedbackStatus::Pending).unwrap(),
            "\"pending\""
        );
        assert_eq!(
            serde_json::to_string(&FeedbackStatus::Processing).unwrap(),
            "\"processing\""
        );
        assert_eq!(
            serde_json::to_string(&FeedbackStatus::Completed).unwrap(),
            "\"completed\""
        );
        assert_eq!(
            serde_json::to_string(&FeedbackStatus::Closed).unwrap(),
            "\"closed\""
        );
    }

    #[test]
    fn test_app_badge() {
        let badge = AppBadge {
            badge_type: Some(BadgeType::Number),
            content: Some("5".to_string()),
        };
        let json = serde_json::to_string(&badge).unwrap();
        assert!(json.contains("number"));
        assert!(json.contains("5"));
    }

    #[test]
    fn test_badge_type_enum() {
        assert_eq!(
            serde_json::to_string(&BadgeType::Number).unwrap(),
            "\"number\""
        );
        assert_eq!(serde_json::to_string(&BadgeType::Dot).unwrap(), "\"dot\"");
        assert_eq!(
            serde_json::to_string(&BadgeType::Clear).unwrap(),
            "\"clear\""
        );
    }

    #[test]
    fn test_order() {
        let order = Order {
            order_id: Some("order123".to_string()),
            status: Some(OrderStatus::Paid),
            pricing_plan_id: Some("plan456".to_string()),
            quantity: Some(10),
            purchase_time: Some("2024-01-01T00:00:00Z".to_string()),
            expire_time: Some("2025-01-01T00:00:00Z".to_string()),
        };
        let json = serde_json::to_string(&order).unwrap();
        assert!(json.contains("order123"));
        assert!(json.contains("paid"));
        assert!(json.contains("plan456"));
        assert!(json.contains("10"));
    }

    #[test]
    fn test_order_status_enum() {
        assert_eq!(
            serde_json::to_string(&OrderStatus::Pending).unwrap(),
            "\"pending\""
        );
        assert_eq!(
            serde_json::to_string(&OrderStatus::Paid).unwrap(),
            "\"paid\""
        );
        assert_eq!(
            serde_json::to_string(&OrderStatus::Cancelled).unwrap(),
            "\"cancelled\""
        );
        assert_eq!(
            serde_json::to_string(&OrderStatus::Expired).unwrap(),
            "\"expired\""
        );
    }

    #[test]
    fn test_pricing_plan() {
        let plan = PricingPlan {
            pricing_plan_id: Some("plan123".to_string()),
            plan_name: Some("专业版".to_string()),
            description: Some("适合中型团队".to_string()),
            price: Some("99.00".to_string()),
            billing_cycle: Some(BillingCycle::Monthly),
        };
        let json = serde_json::to_string(&plan).unwrap();
        assert!(json.contains("plan123"));
        assert!(json.contains("专业版"));
        assert!(json.contains("99.00"));
        assert!(json.contains("monthly"));
    }

    #[test]
    fn test_billing_cycle_enum() {
        assert_eq!(
            serde_json::to_string(&BillingCycle::Monthly).unwrap(),
            "\"monthly\""
        );
        assert_eq!(
            serde_json::to_string(&BillingCycle::Yearly).unwrap(),
            "\"yearly\""
        );
        assert_eq!(
            serde_json::to_string(&BillingCycle::Once).unwrap(),
            "\"once\""
        );
    }

    #[test]
    fn test_audit_status() {
        let status = AuditStatus {
            status: Some(AuditResult::Approved),
            comment: Some("应用符合规范".to_string()),
            audit_time: Some("2024-01-01T14:00:00Z".to_string()),
        };
        let json = serde_json::to_string(&status).unwrap();
        assert!(json.contains("approved"));
        assert!(json.contains("应用符合规范"));
    }

    #[test]
    fn test_audit_result_enum() {
        assert_eq!(
            serde_json::to_string(&AuditResult::Pending).unwrap(),
            "\"pending\""
        );
        assert_eq!(
            serde_json::to_string(&AuditResult::Approved).unwrap(),
            "\"approved\""
        );
        assert_eq!(
            serde_json::to_string(&AuditResult::Rejected).unwrap(),
            "\"rejected\""
        );
    }

    #[test]
    fn test_contacts_range() {
        let range = ContactsRange {
            range_type: Some(ContactsRangeType::Some),
            department_list: Some(vec!["dept1".to_string(), "dept2".to_string()]),
            user_list: Some(vec!["user1".to_string()]),
        };
        let json = serde_json::to_string(&range).unwrap();
        assert!(json.contains("some"));
        assert!(json.contains("dept1"));
        assert!(json.contains("user1"));
    }

    #[test]
    fn test_contacts_range_type_enum() {
        assert_eq!(
            serde_json::to_string(&ContactsRangeType::All).unwrap(),
            "\"all\""
        );
        assert_eq!(
            serde_json::to_string(&ContactsRangeType::Some).unwrap(),
            "\"some\""
        );
        assert_eq!(
            serde_json::to_string(&ContactsRangeType::AdminRange).unwrap(),
            "\"admin_range\""
        );
    }

    #[test]
    fn test_minimal_structs() {
        let minimal_app = Application {
            app_id: Some("minimal".to_string()),
            app_name: Some("最小应用".to_string()),
            description: None,
            avatar_url: None,
            app_type: None,
            status: None,
            create_time: None,
            update_time: None,
        };
        let json = serde_json::to_string(&minimal_app).unwrap();
        assert!(json.contains("minimal"));
        assert!(json.contains("最小应用"));
        assert!(!json.contains("description"));
    }
}