openlark-docs 0.16.1

飞书开放平台云文档服务模块 - 文档、表格、知识库API (202 APIs, 100% 覆盖,不含旧版本)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
/// Cloud Docs云文档服务数据模型
///
/// 定义企业文档管理的核心数据结构,包括:
/// - 文档基础信息管理
/// - 文档版本控制
/// - 权限管理
/// - 评论和协作
/// - 文档模板
/// - 文档搜索
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

use openlark_core::api::Response;

// ==================== 基础数据类型 ====================

/// 文档类型
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DocumentType {
    /// 文本文档
    Doc,
    /// 表格
    Sheet,
    /// 幻灯片
    Slide,
    /// 思维导图
    Mindnote,
    /// 白板
    Bitable,
    /// 流程图
    Docx,
    /// 其他
    Other,
}

/// 文档状态
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DocumentStatus {
    /// 草稿
    Draft,
    /// 已发布
    Published,
    /// 已归档
    Archived,
    /// 已删除
    Deleted,
}

/// 权限类型
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PermissionType {
    /// 只读
    View,
    /// 可编辑
    Edit,
    /// 管理员
    Admin,
    /// 所有者
    Owner,
}

/// 评论类型
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CommentType {
    /// 普通评论
    Normal,
    /// 建议
    Suggestion,
    /// 问题
    Question,
    /// 解决方案
    Solution,
}

// ==================== 文档基础信息 ====================

/// 文档基础信息
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Document {
    /// 文档ID
    pub document_id: String,
    /// 文档标题
    pub title: String,
    /// 文档类型
    pub document_type: DocumentType,
    /// 文档状态
    pub status: DocumentStatus,
    /// 文档所有者ID
    pub owner_id: String,
    /// 文档所有者名称
    pub owner_name: Option<String>,
    /// 创建时间
    pub create_time: DateTime<Utc>,
    /// 最后修改时间
    pub update_time: DateTime<Utc>,
    /// 文档版本号
    pub version: i32,
    /// 文档大小(字节)
    pub size: i64,
    /// 文档描述
    pub description: Option<String>,
    /// 文档标签
    pub tags: Option<Vec<String>>,
    /// 文档封面图片URL
    pub cover_url: Option<String>,
    /// 文档预览URL
    pub preview_url: Option<String>,
    /// 文档分享链接
    pub share_url: Option<String>,
    /// 文档阅读次数
    pub view_count: i32,
    /// 文档编辑次数
    pub edit_count: i32,
    /// 文档评论次数
    pub comment_count: i32,
    /// 文档收藏次数
    favorite_count: i32,
    /// 文档所属文件夹ID
    pub folder_id: Option<String>,
    /// 文档权限
    pub permissions: Option<DocumentPermissions>,
    /// 文档协作者列表
    pub collaborators: Option<Vec<Collaborator>>,
    /// 文档扩展属性
    pub extra_properties: Option<serde_json::Value>,
}

/// 文档权限
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DocumentPermissions {
    /// 是否公开
    pub is_public: bool,
    /// 权限列表
    pub permissions: Vec<DocumentPermission>,
    /// 继承权限
    pub inherit_permissions: bool,
}

/// 文档权限条目
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DocumentPermission {
    /// 用户/用户组ID
    pub principal_id: String,
    /// 用户/用户组类型
    pub principal_type: PrincipalType,
    /// 权限类型
    pub permission_type: PermissionType,
    /// 权限过期时间
    pub expire_time: Option<DateTime<Utc>>,
}

/// 用户/用户组类型
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PrincipalType {
    /// 用户
    User,
    /// 用户组
    Group,
    /// 部门
    Department,
    /// 组织
    Organization,
}

/// 协作者信息
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Collaborator {
    /// 用户ID
    pub user_id: String,
    /// 用户名称
    pub name: String,
    /// 用户头像
    pub avatar: Option<String>,
    /// 邮箱
    pub email: Option<String>,
    /// 权限类型
    pub permission: PermissionType,
    /// 加入时间
    pub join_time: DateTime<Utc>,
    /// 最后活跃时间
    pub last_active_time: Option<DateTime<Utc>>,
}

// ==================== 文档版本管理 ====================

/// 文档版本
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DocumentVersion {
    /// 版本ID
    pub version_id: String,
    /// 文档ID
    pub document_id: String,
    /// 版本号
    pub version: i32,
    /// 版本标题
    pub title: String,
    /// 版本描述
    pub description: Option<String>,
    /// 创建者ID
    pub creator_id: String,
    /// 创建者名称
    pub creator_name: String,
    /// 创建时间
    pub create_time: DateTime<Utc>,
    /// 版本大小
    pub size: i64,
    /// 版本差异
    pub diff: Option<String>,
    /// 版本标签
    pub tags: Option<Vec<String>>,
    /// 是否为主要版本
    pub is_major: bool,
    /// 版本状态
    pub status: VersionStatus,
    /// 版本备注
    pub notes: Option<String>,
}

/// 版本状态
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum VersionStatus {
    /// 进行中
    InProgress,
    /// 已完成
    Completed,
    /// 已废弃
    Deprecated,
}

// ==================== 文件夹管理 ====================

/// 文件夹
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Folder {
    /// 文件夹ID
    pub folder_id: String,
    /// 文件夹名称
    pub name: String,
    /// 父文件夹ID
    pub parent_folder_id: Option<String>,
    /// 文件夹所有者ID
    pub owner_id: String,
    /// 文件夹所有者名称
    pub owner_name: Option<String>,
    /// 文件夹描述
    pub description: Option<String>,
    /// 文件夹图标
    pub icon: Option<String>,
    /// 文件夹颜色
    pub color: Option<String>,
    /// 创建时间
    pub create_time: DateTime<Utc>,
    /// 更新时间
    pub update_time: DateTime<Utc>,
    /// 文件夹中的文档数量
    pub document_count: i32,
    /// 子文件夹数量
    pub subfolder_count: i32,
    /// 文件夹权限
    pub permissions: Option<FolderPermissions>,
    /// 文件夹排序
    pub order: Option<i32>,
    /// 文件夹状态
    pub status: FolderStatus,
}

/// 文件夹权限
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct FolderPermissions {
    /// 是否公开
    pub is_public: bool,
    /// 权限列表
    pub permissions: Vec<FolderPermission>,
    /// 继承权限
    pub inherit_permissions: bool,
}

/// 文件夹权限条目
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FolderPermission {
    /// 用户/用户组ID
    pub principal_id: String,
    /// 用户/用户组类型
    pub principal_type: PrincipalType,
    /// 权限类型
    pub permission_type: FolderPermissionType,
    /// 权限过期时间
    pub expire_time: Option<DateTime<Utc>>,
}

/// 文件夹权限类型
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FolderPermissionType {
    /// 只读
    View,
    /// 可编辑
    Edit,
    /// 管理员
    Admin,
    /// 创建者
    Creator,
}

/// 文件夹状态
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FolderStatus {
    /// 正常
    Active,
    /// 已归档
    Archived,
    /// 已删除
    Deleted,
}

// ==================== 评论和协作 ====================

/// 文档评论
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Comment {
    /// 评论ID
    pub comment_id: String,
    /// 文档ID
    pub document_id: String,
    /// 评论者ID
    pub user_id: String,
    /// 评论者名称
    pub user_name: String,
    /// 评论者头像
    pub avatar: Option<String>,
    /// 评论内容
    pub content: String,
    /// 评论类型
    pub comment_type: CommentType,
    /// 父评论ID(回复时使用)
    pub parent_comment_id: Option<String>,
    /// 评论位置(文档中的位置)
    pub position: Option<CommentPosition>,
    /// 评论被引用次数
    pub reference_count: i32,
    /// 评论点赞数
    pub like_count: i32,
    /// 评论是否已解决
    pub is_resolved: bool,
    /// 创建时间
    pub create_time: DateTime<Utc>,
    /// 更新时间
    pub update_time: DateTime<Utc>,
    /// 评论回复列表
    pub replies: Option<Vec<Comment>>,
}

/// 评论位置
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CommentPosition {
    /// 页码
    pub page_number: Option<i32>,
    /// 位置X坐标
    pub x: Option<f64>,
    /// 位置Y坐标
    pub y: Option<f64>,
    /// 选中范围
    pub selection: Option<TextSelection>,
}

/// 文本选择范围
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct TextSelection {
    /// 起始位置
    pub start: TextPosition,
    /// 结束位置
    pub end: TextPosition,
    /// 选中内容
    pub selected_text: Option<String>,
}

/// 文本位置
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct TextPosition {
    /// 段落索引
    pub paragraph_index: i32,
    /// 字符偏移
    pub offset: i32,
    /// 行号
    pub line: i32,
    /// 列号
    pub column: i32,
}

// ==================== 文档模板 ====================

/// 文档模板
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DocumentTemplate {
    /// 模板ID
    pub template_id: String,
    /// 模板名称
    pub name: String,
    /// 模板描述
    pub description: Option<String>,
    /// 模板类型
    pub template_type: DocumentType,
    /// 模板分类
    pub category: Option<String>,
    /// 模板标签
    pub tags: Option<Vec<String>>,
    /// 模板封面图片URL
    pub cover_url: Option<String>,
    /// 模板预览URL
    pub preview_url: Option<String>,
    /// 模板创建者ID
    pub creator_id: String,
    /// 模板创建者名称
    pub creator_name: String,
    /// 是否公开模板
    pub is_public: bool,
    /// 模板使用次数
    pub usage_count: i32,
    /// 模板评分
    pub rating: Option<f64>,
    /// 创建时间
    pub create_time: DateTime<Utc>,
    /// 更新时间
    pub update_time: DateTime<Utc>,
    /// 模板内容
    pub content: Option<serde_json::Value>,
}

// ==================== 搜索和推荐 ====================

/// 文档搜索结果
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DocumentSearchResult {
    /// 文档ID
    pub document_id: String,
    /// 文档标题
    pub title: String,
    /// 文档类型
    pub document_type: DocumentType,
    /// 文档状态
    pub status: DocumentStatus,
    /// 文档所有者ID
    pub owner_id: String,
    /// 文档所有者名称
    pub owner_name: Option<String>,
    /// 文档描述
    pub description: Option<String>,
    /// 文档标签
    pub tags: Option<Vec<String>>,
    /// 创建时间
    pub create_time: DateTime<Utc>,
    /// 更新时间
    pub update_time: DateTime<Utc>,
    /// 文档大小
    pub size: i64,
    /// 搜索相关性得分
    pub relevance_score: f64,
    /// 搜索高亮内容
    pub highlights: Option<Vec<SearchHighlight>>,
}

/// 搜索高亮
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SearchHighlight {
    /// 字段名称
    pub field: String,
    /// 高亮片段
    pub fragments: Vec<String>,
    /// 高亮开始位置
    pub ranges: Vec<HighlightRange>,
}

/// 高亮范围
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct HighlightRange {
    /// 开始位置
    pub start: i32,
    /// 结束位置
    pub end: i32,
}

/// 文档推荐
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DocumentRecommendation {
    /// 文档ID
    pub document_id: String,
    /// 文档标题
    pub title: String,
    /// 推荐原因
    pub reason: String,
    /// 推荐类型
    pub recommendation_type: RecommendationType,
    /// 推荐得分
    pub score: f64,
    /// 推荐时间
    pub recommend_time: DateTime<Utc>,
}

/// 推荐类型
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum RecommendationType {
    /// 协作推荐
    Collaboration,
    /// 标签推荐
    Tag,
    /// 搜索历史推荐
    SearchHistory,
    /// 热门推荐
    Popular,
    /// 相似文档推荐
    Similar,
}

// ==================== 请求响应模型 ====================

/// 创建文档请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateDocumentRequest {
    /// 文档标题
    pub title: String,
    /// 文档类型
    pub document_type: DocumentType,
    /// 文档内容
    pub content: Option<serde_json::Value>,
    /// 文档描述
    pub description: Option<String>,
    /// 文档标签
    pub tags: Option<Vec<String>>,
    /// 所属文件夹ID
    pub folder_id: Option<String>,
    /// 权限设置
    pub permissions: Option<DocumentPermissions>,
    /// 协作者列表
    pub collaborators: Option<Vec<Collaborator>>,
}

/// 更新文档请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateDocumentRequest {
    /// 文档ID
    pub document_id: String,
    /// 文档标题
    pub title: Option<String>,
    /// 文档描述
    pub description: Option<String>,
    /// 文档标签
    pub tags: Option<Vec<String>>,
    /// 文档状态
    pub status: Option<DocumentStatus>,
    /// 所属文件夹ID
    pub folder_id: Option<String>,
}

/// 查询文档请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryDocumentsRequest {
    /// 文件夹ID筛选
    pub folder_id: Option<String>,
    /// 文档类型筛选
    pub document_type: Option<DocumentType>,
    /// 文档状态筛选
    pub status: Option<DocumentStatus>,
    /// 所有者ID筛选
    pub owner_id: Option<String>,
    /// 标签筛选
    pub tags: Option<Vec<String>>,
    /// 关键词搜索
    pub keyword: Option<String>,
    /// 排序方式
    pub sort_by: Option<SortBy>,
    /// 排序方向
    pub sort_direction: Option<SortDirection>,
    /// 分页大小
    pub page_size: Option<i32>,
    /// 页面标记
    pub page_token: Option<String>,
}

/// 排序字段
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SortBy {
    /// 创建时间
    CreateTime,
    /// 更新时间
    UpdateTime,
    /// 标题
    Title,
    /// 大小
    Size,
    /// 阅读次数
    ViewCount,
    /// 编辑次数
    EditCount,
    /// 评论次数
    CommentCount,
    /// 收藏次数
    FavoriteCount,
}

/// 排序方向
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SortDirection {
    /// 升序
    Asc,
    /// 降序
    Desc,
}

/// 搜索文档请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchDocumentsRequest {
    /// 搜索关键词
    pub query: String,
    /// 搜索范围
    pub search_scope: Option<SearchScope>,
    /// 文档类型筛选
    pub document_type: Option<DocumentType>,
    /// 文档状态筛选
    pub status: Option<DocumentStatus>,
    /// 所有者ID筛选
    pub owner_id: Option<String>,
    /// 标签筛选
    pub tags: Option<Vec<String>>,
    /// 搜索方式
    pub search_type: Option<SearchType>,
    /// 排序方式
    pub sort_by: Option<SortBy>,
    /// 排序方向
    pub sort_direction: Option<SortDirection>,
    /// 分页大小
    pub page_size: Option<i32>,
    /// 页面标记
    pub page_token: Option<String>,
}

/// 搜索范围
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SearchScope {
    /// 标题
    Title,
    /// 内容
    Content,
    /// 标签
    Tags,
    /// 描述
    Description,
    /// 作者
    Author,
    /// 全文
    FullText,
}

/// 搜索方式
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SearchType {
    /// 模糊搜索
    Fuzzy,
    /// 精确搜索
    Exact,
    /// 正则表达式
    Regex,
}

/// 创建评论请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateCommentRequest {
    /// 文档ID
    pub document_id: String,
    /// 评论内容
    pub content: String,
    /// 评论类型
    pub comment_type: CommentType,
    /// 父评论ID(回复时使用)
    pub parent_comment_id: Option<String>,
    /// 评论位置
    pub position: Option<CommentPosition>,
    /// 提及用户
    pub mentions: Option<Vec<String>>,
}

/// 查询评论请求
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryCommentsRequest {
    /// 文档ID
    pub document_id: String,
    /// 父评论ID筛选
    pub parent_comment_id: Option<String>,
    /// 评论类型筛选
    pub comment_type: Option<CommentType>,
    /// 是否已解决筛选
    pub is_resolved: Option<bool>,
    /// 排序方式
    pub sort_by: Option<SortBy>,
    /// 排序方向
    pub sort_direction: Option<SortDirection>,
    /// 分页大小
    pub page_size: Option<i32>,
    /// 页面标记
    pub page_token: Option<String>,
}

/// 分页响应基础结构
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PageResponse<T> {
    /// 数据项列表
    pub items: Vec<T>,
    /// 分页标记,用于获取下一页数据
    #[serde(skip_serializing_if = "Option::is_none")]
    pub page_token: Option<String>,
    /// 是否还有更多数据
    #[serde(skip_serializing_if = "Option::is_none")]
    pub has_more: Option<bool>,
    /// 总数
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total: Option<i32>,
}

/// 基础响应结构
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Response<T> {
    /// 状态码
    pub code: i32,
    /// 消息
    pub msg: String,
    /// 数据
    pub data: Option<T>,
}

/// 文档列表响应
pub type DocumentListResponse = Response<PageResponse<Document>>;

/// 文档详情响应
pub type DocumentResponse = Response<Document>;

/// 文件夹列表响应
pub type FolderListResponse = Response<PageResponse<Folder>>;

/// 评论列表响应
pub type CommentListResponse = Response<PageResponse<Comment>>;

/// 搜索结果响应
pub type SearchResponse = Response<PageResponse<DocumentSearchResult>>;

/// 推荐文档响应
pub type RecommendResponse = Response<Vec<DocumentRecommendation>>;

/// 文档版本列表响应
pub type VersionListResponse = Response<PageResponse<DocumentVersion>>;

/// 模板列表响应
pub type TemplateListResponse = Response<PageResponse<DocumentTemplate>>;

/// 空响应
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmptyResponse {
    pub code: i32,
    pub msg: String,
}

// 实现Default trait
impl Default for DocumentType {
    fn default() -> Self {
        DocumentType::Doc
    }
}

impl Default for DocumentStatus {
    fn default() -> Self {
        DocumentStatus::Draft
    }
}

impl Default for PermissionType {
    fn default() -> Self {
        PermissionType::View
    }
}

impl Default for CommentType {
    fn default() -> Self {
        CommentType::Normal
    }
}

impl Default for PrincipalType {
    fn default() -> Self {
        PrincipalType::User
    }
}

impl Default for VersionStatus {
    fn default() -> Self {
        VersionStatus::InProgress
    }
}

impl Default for FolderStatus {
    fn default() -> Self {
        FolderStatus::Active
    }
}

impl Default for FolderPermissionType {
    fn default() -> Self {
        FolderPermissionType::View
    }
}

impl Default for SortBy {
    fn default() -> Self {
        SortBy::CreateTime
    }
}

impl Default for SortDirection {
    fn default() -> Self {
        SortDirection::Desc
    }
}

impl Default for SearchScope {
    fn default() -> Self {
        SearchScope::FullText
    }
}

impl Default for SearchType {
    fn default() -> Self {
        SearchType::Fuzzy
    }
}

impl Default for RecommendationType {
    fn default() -> Self {
        RecommendationType::Collaboration
    }
}

impl Default for CreateDocumentRequest {
    fn default() -> Self {
        Self {
            title: String::new(),
            document_type: DocumentType::Doc,
            content: None,
            description: None,
            tags: None,
            folder_id: None,
            permissions: None,
            collaborators: None,
        }
    }
}

impl Default for UpdateDocumentRequest {
    fn default() -> Self {
        Self {
            document_id: String::new(),
            title: None,
            description: None,
            tags: None,
            status: None,
            folder_id: None,
        }
    }
}

impl Default for QueryDocumentsRequest {
    fn default() -> Self {
        Self {
            folder_id: None,
            document_type: None,
            status: None,
            owner_id: None,
            tags: None,
            keyword: None,
            sort_by: None,
            sort_direction: None,
            page_size: None,
            page_token: None,
        }
    }
}

impl Default for SearchDocumentsRequest {
    fn default() -> Self {
        Self {
            query: String::new(),
            search_scope: None,
            document_type: None,
            status: None,
            owner_id: None,
            tags: None,
            search_type: None,
            sort_by: None,
            sort_direction: None,
            page_size: None,
            page_token: None,
        }
    }
}

impl Default for CreateCommentRequest {
    fn default() -> Self {
        Self {
            document_id: String::new(),
            content: String::new(),
            comment_type: CommentType::Normal,
            parent_comment_id: None,
            position: None,
            mentions: None,
        }
    }
}

impl Default for QueryCommentsRequest {
    fn default() -> Self {
        Self {
            document_id: String::new(),
            parent_comment_id: None,
            comment_type: None,
            is_resolved: None,
            sort_by: None,
            sort_direction: None,
            page_size: None,
            page_token: None,
        }
    }
}

impl Default for PageResponse<Document> {
    fn default() -> Self {
        Self {
            items: vec![],
            page_token: None,
            has_more: Some(false),
            total: Some(0),
        }
    }
}

impl Default for PageResponse<Folder> {
    fn default() -> Self {
        Self {
            items: vec![],
            page_token: None,
            has_more: Some(false),
            total: Some(0),
        }
    }
}

impl Default for PageResponse<Comment> {
    fn default() -> Self {
        Self {
            items: vec![],
            page_token: None,
            has_more: Some(false),
            total: Some(0),
        }
    }
}

impl Default for PageResponse<DocumentSearchResult> {
    fn default() -> Self {
        Self {
            items: vec![],
            page_token: None,
            has_more: Some(false),
            total: Some(0),
        }
    }
}

impl Default for Response<Document> {
    fn default() -> Self {
        Self {
            code: 0,
            msg: String::new(),
            data: None,
        }
    }
}

impl Default for Response<EmptyResponse> {
    fn default() -> Self {
        Self {
            code: 0,
            msg: String::new(),
            data: Some(EmptyResponse::default()),
        }
    }
}

impl Default for EmptyResponse {
    fn default() -> Self {
        Self {
            code: 0,
            msg: String::new(),
        }
    }
}

// ==================== 补充缺失的类型 ====================

/// 文件夹内容类型
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FolderContentType {
    /// 文件夹
    Folder,
    /// 文档
    Document,
    /// 全部
    All,
}

/// 评论反应
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CommentReaction {
    /// 反应ID
    pub reaction_id: String,
    /// 评论ID
    pub comment_id: String,
    /// 用户ID
    pub user_id: String,
    /// 反应类型
    pub reaction_type: String,
    /// 创建时间
    pub create_time: DateTime<Utc>,
}

/// 搜索日期范围
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchDateRange {
    /// 开始日期
    pub start_date: DateTime<Utc>,
    /// 结束日期
    pub end_date: DateTime<Utc>,
}

/// 搜索排序方式
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SearchSortBy {
    /// 相关度
    Relevance,
    /// 创建时间
    CreateTime,
    /// 更新时间
    UpdateTime,
    /// 标题
    Title,
}

/// 推荐类型
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum RecommendType {
    /// 协作推荐
    Collaboration,
    /// 热门文档
    Popular,
    /// 相关推荐
    Related,
    /// 最近访问
    Recent,
}

/// 模板参数
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct TemplateParameter {
    /// 参数名称
    pub name: String,
    /// 参数类型
    pub param_type: String,
    /// 参数描述
    pub description: Option<String>,
    /// 是否必填
    pub required: bool,
    /// 默认值
    pub default_value: Option<String>,
}

/// 批量操作失败项
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct BatchFailureItem {
    /// 项目ID
    pub item_id: String,
    /// 错误代码
    pub error_code: i32,
    /// 错误消息
    pub error_message: String,
}

/// 批量操作结果
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct BatchOperationResult {
    /// 成功数量
    pub success_count: i32,
    /// 失败数量
    pub failure_count: i32,
    /// 成功项目ID列表
    pub success_items: Vec<String>,
    /// 失败项目详情
    pub failure_items: Vec<BatchFailureItem>,
}

/// 版本差异
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct VersionDiff {
    /// 源版本号
    pub from_version: i32,
    /// 目标版本号
    pub to_version: i32,
    /// 差异类型
    pub diff_type: String,
    /// 差异内容
    pub diff_content: String,
    /// 变更行数
    pub changed_lines: i32,
    /// 添加行数
    pub added_lines: i32,
    /// 删除行数
    pub deleted_lines: i32,
}

/// 搜索结果
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SearchResult {
    /// 搜索结果项
    pub items: Vec<SearchItem>,
    /// 总数
    pub total: i32,
    /// 搜索用时
    pub search_time: f64,
    /// 搜索建议
    pub suggestions: Option<Vec<String>>,
}

/// 搜索结果项
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SearchItem {
    /// 文档ID
    pub document_id: String,
    /// 文档标题
    pub title: String,
    /// 文档类型
    pub document_type: DocumentType,
    /// 所有者ID
    pub owner_id: String,
    /// 更新时间
    pub update_time: DateTime<Utc>,
    /// 摘要
    pub snippet: Option<String>,
    /// 高亮片段
    pub highlights: Option<Vec<String>>,
    /// 相关度评分
    pub score: f64,
}

/// 搜索历史项
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SearchHistoryItem {
    /// 搜索关键词
    pub keyword: String,
    /// 搜索时间
    pub search_time: DateTime<Utc>,
    /// 搜索结果数量
    pub result_count: i32,
}

/// 推荐结果
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct RecommendResult {
    /// 推荐项目
    pub items: Vec<RecommendItem>,
    /// 推荐类型
    pub recommend_type: RecommendType,
    /// 推荐原因
    pub reason: String,
}

/// 推荐项目
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct RecommendItem {
    /// 文档ID
    pub document_id: String,
    /// 文档标题
    pub title: String,
    /// 文档类型
    pub document_type: DocumentType,
    /// 所有者ID
    pub owner_id: String,
    /// 更新时间
    pub update_time: DateTime<Utc>,
    /// 推荐评分
    pub score: f64,
    /// 推荐原因
    pub reason: Option<String>,
}

/// 文件夹内容项
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct FolderContent {
    /// 内容ID
    pub id: String,
    /// 内容名称
    pub name: String,
    /// 内容类型
    pub content_type: FolderContentType,
    /// 所有者ID
    pub owner_id: String,
    /// 创建时间
    pub create_time: DateTime<Utc>,
    /// 更新时间
    pub update_time: DateTime<Utc>,
    /// 文件大小(文档时使用)
    pub size: Option<i64>,
    /// 文档类型(文档时使用)
    pub document_type: Option<DocumentType>,
}

// Default实现
impl Default for FolderContentType {
    fn default() -> Self {
        FolderContentType::All
    }
}

impl Default for SearchSortBy {
    fn default() -> Self {
        SearchSortBy::Relevance
    }
}

impl Default for RecommendType {
    fn default() -> Self {
        RecommendType::Collaboration
    }
}

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

    #[test]
    fn test_serialization_roundtrip() {
        // 基础序列化测试
        let json = r#"{"test": "value"}"#;
        assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
    }

    #[test]
    fn test_deserialization_from_json() {
        // 基础反序列化测试
        let json = r#"{"field": "data"}"#;
        let value: serde_json::Value = serde_json::from_str(json).expect("JSON 反序列化失败");
        assert_eq!(value["field"], "data");
    }
}