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

/// 分页响应基础结构
#[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>,
}

/// OKR 周期状态
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PeriodStatus {
    /// 草稿状态
    Draft,
    /// 进行中
    Active,
    /// 已结束
    Ended,
    /// 已暂停
    Paused,
}

/// OKR 状态
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum OkrStatus {
    /// 正常
    Normal,
    /// 已删除
    Deleted,
    /// 草稿
    Draft,
}

/// 进展记录类型
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ProgressRecordType {
    /// 简单更新
    Simple,
    /// 详细更新
    Detail,
    /// 图片更新
    Image,
}

/// Key Result 类型
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum KeyResultType {
    /// 数值型
    Numeric,
    /// 百分比型
    Percentage,
    /// 里程碑型
    Milestone,
}

/// 多语言文本
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct I18nText {
    /// 中文文本
    #[serde(skip_serializing_if = "Option::is_none")]
    pub zh_cn: Option<String>,
    /// 英文文本
    #[serde(skip_serializing_if = "Option::is_none")]
    pub en_us: Option<String>,
    /// 日文文本
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ja_jp: Option<String>,
}

/// 用户信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
    /// 用户ID
    pub user_id: String,
    /// 用户名称
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<I18nText>,
    /// 用户头像
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar: Option<String>,
}

/// OKR 周期
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Period {
    /// 周期ID
    pub period_id: String,
    /// 周期名称
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<I18nText>,
    /// 周期状态
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<PeriodStatus>,
    /// 开始时间(毫秒时间戳)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub start_time: Option<i64>,
    /// 结束时间(毫秒时间戳)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub end_time: Option<i64>,
    /// 创建时间(毫秒时间戳)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create_time: Option<i64>,
    /// 更新时间(毫秒时间戳)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub modify_time: Option<i64>,
}

/// OKR 周期规则
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PeriodRule {
    /// 规则ID
    pub rule_id: String,
    /// 周期ID
    pub period_id: String,
    /// 规则类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rule_type: Option<String>,
    /// 规则配置
    #[serde(skip_serializing_if = "Option::is_none")]
    pub config: Option<serde_json::Value>,
}

/// Key Result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KeyResult {
    /// Key Result ID
    pub kr_id: String,
    /// 内容
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<I18nText>,
    /// 类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub kr_type: Option<KeyResultType>,
    /// 当前值
    #[serde(skip_serializing_if = "Option::is_none")]
    pub current_value: Option<f64>,
    /// 目标值
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target_value: Option<f64>,
    /// 进度百分比
    #[serde(skip_serializing_if = "Option::is_none")]
    pub progress_rate: Option<f64>,
    /// 完成状态
    #[serde(skip_serializing_if = "Option::is_none")]
    pub completed: Option<bool>,
}

/// Objective
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Objective {
    /// Objective ID
    pub objective_id: String,
    /// 内容
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<I18nText>,
    /// 进度百分比
    #[serde(skip_serializing_if = "Option::is_none")]
    pub progress_rate: Option<f64>,
    /// Key Results 列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub key_results: Option<Vec<KeyResult>>,
}

/// OKR
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Okr {
    /// OKR ID
    pub okr_id: String,
    /// 用户ID
    pub user_id: String,
    /// 周期ID
    pub period_id: String,
    /// 状态
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<OkrStatus>,
    /// Objectives 列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub objectives: Option<Vec<Objective>>,
    /// 创建时间(毫秒时间戳)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create_time: Option<i64>,
    /// 更新时间(毫秒时间戳)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub modify_time: Option<i64>,
}

/// 进展记录附件
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProgressAttachment {
    /// 附件ID
    pub attachment_id: String,
    /// 附件名称
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// 附件URL
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    /// 附件类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub file_type: Option<String>,
    /// 文件大小
    #[serde(skip_serializing_if = "Option::is_none")]
    pub size: Option<i64>,
}

/// 进展记录
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProgressRecord {
    /// 进展记录ID
    pub progress_id: String,
    /// OKR ID
    pub okr_id: String,
    /// 内容
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<String>,
    /// 记录类型
    #[serde(skip_serializing_if = "Option::is_none")]
    pub record_type: Option<ProgressRecordType>,
    /// 进度百分比
    #[serde(skip_serializing_if = "Option::is_none")]
    pub progress_rate: Option<f64>,
    /// 附件列表
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attachments: Option<Vec<ProgressAttachment>>,
    /// 创建者
    #[serde(skip_serializing_if = "Option::is_none")]
    pub creator: Option<User>,
    /// 创建时间(毫秒时间戳)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create_time: Option<i64>,
    /// 更新时间(毫秒时间戳)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub modify_time: Option<i64>,
}

/// OKR 复盘信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Review {
    /// 复盘ID
    pub review_id: String,
    /// OKR ID
    pub okr_id: String,
    /// 周期ID
    pub period_id: String,
    /// 复盘内容
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<String>,
    /// 复盘评分
    #[serde(skip_serializing_if = "Option::is_none")]
    pub score: Option<f64>,
    /// 复盘者
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reviewer: Option<User>,
    /// 创建时间(毫秒时间戳)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create_time: Option<i64>,
}

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

    #[test]
    fn test_period_status_enum() {
        assert_eq!(
            serde_json::to_string(&PeriodStatus::Draft).unwrap(),
            "\"draft\""
        );
        assert_eq!(
            serde_json::to_string(&PeriodStatus::Active).unwrap(),
            "\"active\""
        );
        assert_eq!(
            serde_json::to_string(&PeriodStatus::Ended).unwrap(),
            "\"ended\""
        );
        assert_eq!(
            serde_json::to_string(&PeriodStatus::Paused).unwrap(),
            "\"paused\""
        );
    }

    #[test]
    fn test_okr_status_enum() {
        assert_eq!(
            serde_json::to_string(&OkrStatus::Normal).unwrap(),
            "\"normal\""
        );
        assert_eq!(
            serde_json::to_string(&OkrStatus::Deleted).unwrap(),
            "\"deleted\""
        );
        assert_eq!(
            serde_json::to_string(&OkrStatus::Draft).unwrap(),
            "\"draft\""
        );
    }

    #[test]
    fn test_progress_record_type_enum() {
        assert_eq!(
            serde_json::to_string(&ProgressRecordType::Simple).unwrap(),
            "\"simple\""
        );
        assert_eq!(
            serde_json::to_string(&ProgressRecordType::Detail).unwrap(),
            "\"detail\""
        );
        assert_eq!(
            serde_json::to_string(&ProgressRecordType::Image).unwrap(),
            "\"image\""
        );
    }

    #[test]
    fn test_key_result_type_enum() {
        assert_eq!(
            serde_json::to_string(&KeyResultType::Numeric).unwrap(),
            "\"numeric\""
        );
        assert_eq!(
            serde_json::to_string(&KeyResultType::Percentage).unwrap(),
            "\"percentage\""
        );
        assert_eq!(
            serde_json::to_string(&KeyResultType::Milestone).unwrap(),
            "\"milestone\""
        );
    }

    #[test]
    fn test_i18n_text() {
        let text = I18nText {
            zh_cn: Some("中文内容".to_string()),
            en_us: Some("English content".to_string()),
            ja_jp: Some("日本語の内容".to_string()),
        };

        let json = serde_json::to_string(&text).unwrap();
        assert!(json.contains("中文内容"));
        assert!(json.contains("English content"));
        assert!(json.contains("日本語の内容"));
    }

    #[test]
    fn test_i18n_text_minimal() {
        let text = I18nText {
            zh_cn: Some("仅中文".to_string()),
            en_us: None,
            ja_jp: None,
        };

        let json = serde_json::to_string(&text).unwrap();
        assert!(json.contains("仅中文"));
        assert!(!json.contains("en_us"));
        assert!(!json.contains("ja_jp"));
    }

    #[test]
    fn test_user() {
        let name = I18nText {
            zh_cn: Some("张三".to_string()),
            en_us: Some("Zhang San".to_string()),
            ja_jp: None,
        };

        let user = User {
            user_id: "ou_user123".to_string(),
            name: Some(name),
            avatar: Some("https://example.com/avatar.jpg".to_string()),
        };

        let json = serde_json::to_string(&user).unwrap();
        assert!(json.contains("ou_user123"));
        assert!(json.contains("张三"));
        assert!(json.contains("Zhang San"));
        assert!(json.contains("https://example.com/avatar.jpg"));
    }

    #[test]
    fn test_user_minimal() {
        let user = User {
            user_id: "ou_minimal".to_string(),
            name: None,
            avatar: None,
        };

        let json = serde_json::to_string(&user).unwrap();
        assert!(json.contains("ou_minimal"));
        assert!(!json.contains("name"));
        assert!(!json.contains("avatar"));
    }

    #[test]
    fn test_period() {
        let name = I18nText {
            zh_cn: Some("2024年第一季度".to_string()),
            en_us: Some("Q1 2024".to_string()),
            ja_jp: None,
        };

        let period = Period {
            period_id: "period123".to_string(),
            name: Some(name),
            status: Some(PeriodStatus::Active),
            start_time: Some(1704067200000), // 2024-01-01
            end_time: Some(1711900800000),   // 2024-03-31
            create_time: Some(1703980800000),
            modify_time: Some(1704067200000),
        };

        let json = serde_json::to_string(&period).unwrap();
        assert!(json.contains("period123"));
        assert!(json.contains("2024年第一季度"));
        assert!(json.contains("Q1 2024"));
        assert!(json.contains("\"active\""));
        assert!(json.contains("1704067200000"));
        assert!(json.contains("1711900800000"));
    }

    #[test]
    fn test_period_rule() {
        let config = serde_json::json!({
            "auto_close": true,
            "reminder_days": 7
        });

        let rule = PeriodRule {
            rule_id: "rule123".to_string(),
            period_id: "period123".to_string(),
            rule_type: Some("auto_close".to_string()),
            config: Some(config),
        };

        let json = serde_json::to_string(&rule).unwrap();
        assert!(json.contains("rule123"));
        assert!(json.contains("period123"));
        assert!(json.contains("auto_close"));
        assert!(json.contains("\"reminder_days\":7"));
    }

    #[test]
    fn test_key_result() {
        let content = I18nText {
            zh_cn: Some("提升用户活跃度到80%".to_string()),
            en_us: Some("Increase user activity to 80%".to_string()),
            ja_jp: None,
        };

        let kr = KeyResult {
            kr_id: "kr123".to_string(),
            content: Some(content),
            kr_type: Some(KeyResultType::Percentage),
            current_value: Some(65.5),
            target_value: Some(80.0),
            progress_rate: Some(81.875), // (65.5/80.0) * 100
            completed: Some(false),
        };

        let json = serde_json::to_string(&kr).unwrap();
        assert!(json.contains("kr123"));
        assert!(json.contains("提升用户活跃度到80%"));
        assert!(json.contains("Increase user activity to 80%"));
        assert!(json.contains("\"percentage\""));
        assert!(json.contains("65.5"));
        assert!(json.contains("80.0"));
        assert!(json.contains("81.875"));
        assert!(json.contains("false"));
    }

    #[test]
    fn test_key_result_milestone() {
        let content = I18nText {
            zh_cn: Some("完成产品MVP开发".to_string()),
            en_us: Some("Complete MVP development".to_string()),
            ja_jp: None,
        };

        let kr = KeyResult {
            kr_id: "kr456".to_string(),
            content: Some(content),
            kr_type: Some(KeyResultType::Milestone),
            current_value: None,
            target_value: None,
            progress_rate: Some(75.0),
            completed: Some(false),
        };

        let json = serde_json::to_string(&kr).unwrap();
        assert!(json.contains("kr456"));
        assert!(json.contains("完成产品MVP开发"));
        assert!(json.contains("\"milestone\""));
        assert!(json.contains("75.0"));
        assert!(!json.contains("current_value"));
        assert!(!json.contains("target_value"));
    }

    #[test]
    fn test_objective() {
        let obj_content = I18nText {
            zh_cn: Some("提升产品核心指标".to_string()),
            en_us: Some("Improve core product metrics".to_string()),
            ja_jp: None,
        };

        let kr_content = I18nText {
            zh_cn: Some("DAU增长到10万".to_string()),
            en_us: Some("Grow DAU to 100k".to_string()),
            ja_jp: None,
        };

        let kr = KeyResult {
            kr_id: "kr789".to_string(),
            content: Some(kr_content),
            kr_type: Some(KeyResultType::Numeric),
            current_value: Some(85000.0),
            target_value: Some(100000.0),
            progress_rate: Some(85.0),
            completed: Some(false),
        };

        let objective = Objective {
            objective_id: "obj123".to_string(),
            content: Some(obj_content),
            progress_rate: Some(85.0),
            key_results: Some(vec![kr]),
        };

        let json = serde_json::to_string(&objective).unwrap();
        assert!(json.contains("obj123"));
        assert!(json.contains("提升产品核心指标"));
        assert!(json.contains("Improve core product metrics"));
        assert!(json.contains("kr789"));
        assert!(json.contains("DAU增长到10万"));
        assert!(json.contains("\"numeric\""));
        assert!(json.contains("85000.0"));
        assert!(json.contains("100000.0"));
    }

    #[test]
    fn test_okr() {
        let obj_content = I18nText {
            zh_cn: Some("团队效率提升".to_string()),
            en_us: Some("Team efficiency improvement".to_string()),
            ja_jp: None,
        };

        let objective = Objective {
            objective_id: "obj456".to_string(),
            content: Some(obj_content),
            progress_rate: Some(60.0),
            key_results: Some(vec![]),
        };

        let okr = Okr {
            okr_id: "okr123".to_string(),
            user_id: "ou_user456".to_string(),
            period_id: "period456".to_string(),
            status: Some(OkrStatus::Normal),
            objectives: Some(vec![objective]),
            create_time: Some(1704067200000),
            modify_time: Some(1708646400000),
        };

        let json = serde_json::to_string(&okr).unwrap();
        assert!(json.contains("okr123"));
        assert!(json.contains("ou_user456"));
        assert!(json.contains("period456"));
        assert!(json.contains("\"normal\""));
        assert!(json.contains("obj456"));
        assert!(json.contains("团队效率提升"));
        assert!(json.contains("1704067200000"));
    }

    #[test]
    fn test_progress_attachment() {
        let attachment = ProgressAttachment {
            attachment_id: "att123".to_string(),
            name: Some("进度截图.png".to_string()),
            url: Some("https://example.com/progress.png".to_string()),
            file_type: Some("image/png".to_string()),
            size: Some(1024000),
        };

        let json = serde_json::to_string(&attachment).unwrap();
        assert!(json.contains("att123"));
        assert!(json.contains("进度截图.png"));
        assert!(json.contains("https://example.com/progress.png"));
        assert!(json.contains("image/png"));
        assert!(json.contains("1024000"));
    }

    #[test]
    fn test_progress_record() {
        let creator_name = I18nText {
            zh_cn: Some("李四".to_string()),
            en_us: Some("Li Si".to_string()),
            ja_jp: None,
        };

        let creator = User {
            user_id: "ou_creator123".to_string(),
            name: Some(creator_name),
            avatar: Some("https://example.com/creator.jpg".to_string()),
        };

        let attachment = ProgressAttachment {
            attachment_id: "att456".to_string(),
            name: Some("数据报表.xlsx".to_string()),
            url: Some("https://example.com/report.xlsx".to_string()),
            file_type: Some("application/xlsx".to_string()),
            size: Some(2048000),
        };

        let record = ProgressRecord {
            progress_id: "progress123".to_string(),
            okr_id: "okr456".to_string(),
            content: Some("本周完成了核心功能开发,用户反馈良好".to_string()),
            record_type: Some(ProgressRecordType::Detail),
            progress_rate: Some(75.0),
            attachments: Some(vec![attachment]),
            creator: Some(creator),
            create_time: Some(1708646400000),
            modify_time: Some(1708732800000),
        };

        let json = serde_json::to_string(&record).unwrap();
        assert!(json.contains("progress123"));
        assert!(json.contains("okr456"));
        assert!(json.contains("本周完成了核心功能开发,用户反馈良好"));
        assert!(json.contains("\"detail\""));
        assert!(json.contains("75.0"));
        assert!(json.contains("att456"));
        assert!(json.contains("数据报表.xlsx"));
        assert!(json.contains("ou_creator123"));
        assert!(json.contains("李四"));
    }

    #[test]
    fn test_review() {
        let reviewer_name = I18nText {
            zh_cn: Some("王五".to_string()),
            en_us: Some("Wang Wu".to_string()),
            ja_jp: None,
        };

        let reviewer = User {
            user_id: "ou_reviewer123".to_string(),
            name: Some(reviewer_name),
            avatar: None,
        };

        let review = Review {
            review_id: "review123".to_string(),
            okr_id: "okr789".to_string(),
            period_id: "period789".to_string(),
            content: Some(
                "本季度目标基本达成,团队协作有所提升,下季度需要重点关注效率优化".to_string(),
            ),
            score: Some(8.5),
            reviewer: Some(reviewer),
            create_time: Some(1711900800000),
        };

        let json = serde_json::to_string(&review).unwrap();
        assert!(json.contains("review123"));
        assert!(json.contains("okr789"));
        assert!(json.contains("period789"));
        assert!(json.contains("本季度目标基本达成,团队协作有所提升"));
        assert!(json.contains("8.5"));
        assert!(json.contains("ou_reviewer123"));
        assert!(json.contains("王五"));
        assert!(json.contains("1711900800000"));
    }

    #[test]
    fn test_page_response() {
        let kr = KeyResult {
            kr_id: "kr999".to_string(),
            content: None,
            kr_type: Some(KeyResultType::Numeric),
            current_value: Some(50.0),
            target_value: Some(100.0),
            progress_rate: Some(50.0),
            completed: Some(false),
        };

        let response: PageResponse<KeyResult> = PageResponse {
            items: vec![kr],
            page_token: Some("next_page_token".to_string()),
            has_more: Some(true),
        };

        let json = serde_json::to_string(&response).unwrap();
        assert!(json.contains("kr999"));
        assert!(json.contains("50.0"));
        assert!(json.contains("100.0"));
        assert!(json.contains("next_page_token"));
        assert!(json.contains("\"has_more\":true"));
    }

    #[test]
    fn test_minimal_structs() {
        let minimal_period = Period {
            period_id: "minimal_period".to_string(),
            name: None,
            status: None,
            start_time: None,
            end_time: None,
            create_time: None,
            modify_time: None,
        };

        let json = serde_json::to_string(&minimal_period).unwrap();
        assert!(json.contains("minimal_period"));
        assert!(!json.contains("name"));
        assert!(!json.contains("status"));
        assert!(!json.contains("start_time"));

        let minimal_okr = Okr {
            okr_id: "minimal_okr".to_string(),
            user_id: "minimal_user".to_string(),
            period_id: "minimal_period".to_string(),
            status: None,
            objectives: None,
            create_time: None,
            modify_time: None,
        };

        let okr_json = serde_json::to_string(&minimal_okr).unwrap();
        assert!(okr_json.contains("minimal_okr"));
        assert!(okr_json.contains("minimal_user"));
        assert!(okr_json.contains("minimal_period"));
        assert!(!okr_json.contains("status"));
        assert!(!okr_json.contains("objectives"));
    }
}