nylas-types 0.1.1

Type definitions for Nylas API v3
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
//! Contact types for Nylas API v3
//!
//! Contacts represent people and organizations in email and calendar systems.

use serde::{Deserialize, Serialize};

use crate::common::{ContactId, GrantId};

/// A contact entry.
///
/// Represents a person or organization with contact information.
///
/// # Example
///
/// ```
/// # use nylas_types::{Contact, ContactId, GrantId};
/// let contact = Contact {
///     id: ContactId::new("contact_123"),
///     grant_id: GrantId::new("grant_456"),
///     given_name: Some("John".to_string()),
///     family_name: Some("Doe".to_string()),
///     emails: vec![],
///     phone_numbers: vec![],
///     physical_addresses: vec![],
///     web_pages: vec![],
///     groups: vec![],
///     middle_name: None,
///     suffix: None,
///     nickname: None,
///     birthday: None,
///     company_name: None,
///     job_title: None,
///     manager_name: None,
///     office_location: None,
///     notes: None,
///     picture_url: None,
///     picture: None,
/// };
/// ```
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Contact {
    /// Unique identifier for the contact.
    pub id: ContactId,

    /// Grant ID this contact belongs to.
    pub grant_id: GrantId,

    /// Contact's given name (first name).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub given_name: Option<String>,

    /// Contact's middle name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub middle_name: Option<String>,

    /// Contact's family name (last name).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub family_name: Option<String>,

    /// Name suffix (e.g., "Jr.", "Sr.", "III").
    #[serde(skip_serializing_if = "Option::is_none")]
    pub suffix: Option<String>,

    /// Contact's nickname.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nickname: Option<String>,

    /// Birthday in YYYY-MM-DD format.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub birthday: Option<String>,

    /// Company name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub company_name: Option<String>,

    /// Job title.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub job_title: Option<String>,

    /// Manager's name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub manager_name: Option<String>,

    /// Office location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub office_location: Option<String>,

    /// Notes about the contact.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub notes: Option<String>,

    /// URL to contact's picture.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub picture_url: Option<String>,

    /// Base64-encoded contact picture.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub picture: Option<String>,

    /// List of email addresses.
    #[serde(default)]
    pub emails: Vec<ContactEmail>,

    /// List of phone numbers.
    #[serde(default)]
    pub phone_numbers: Vec<ContactPhone>,

    /// List of physical addresses.
    #[serde(default)]
    pub physical_addresses: Vec<ContactAddress>,

    /// List of web pages.
    #[serde(default)]
    pub web_pages: Vec<ContactWebPage>,

    /// List of groups this contact belongs to.
    #[serde(default)]
    pub groups: Vec<ContactGroup>,
}

/// An email address for a contact.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ContactEmail {
    /// Email address type (e.g., "work", "home", "other").
    #[serde(skip_serializing_if = "Option::is_none", rename = "type")]
    pub email_type: Option<String>,

    /// The email address.
    pub email: String,
}

/// A phone number for a contact.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ContactPhone {
    /// Phone number type (e.g., "work", "home", "mobile", "other").
    #[serde(skip_serializing_if = "Option::is_none", rename = "type")]
    pub phone_type: Option<String>,

    /// The phone number.
    pub number: String,
}

/// A physical address for a contact.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ContactAddress {
    /// Address type (e.g., "work", "home", "other").
    #[serde(skip_serializing_if = "Option::is_none", rename = "type")]
    pub address_type: Option<String>,

    /// Street address.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub street_address: Option<String>,

    /// City.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub city: Option<String>,

    /// State or province.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub state: Option<String>,

    /// Postal code.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub postal_code: Option<String>,

    /// Country.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub country: Option<String>,
}

/// A web page for a contact.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ContactWebPage {
    /// Web page type (e.g., "homepage", "blog", "profile", "other").
    #[serde(skip_serializing_if = "Option::is_none", rename = "type")]
    pub page_type: Option<String>,

    /// The URL.
    pub url: String,
}

/// A group that a contact belongs to.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ContactGroup {
    /// Group ID.
    pub id: String,

    /// Group name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,

    /// Group path.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub path: Option<String>,
}

/// Request to create a new contact.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CreateContactRequest {
    /// Contact's given name (first name).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub given_name: Option<String>,

    /// Contact's middle name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub middle_name: Option<String>,

    /// Contact's family name (last name).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub family_name: Option<String>,

    /// Name suffix.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub suffix: Option<String>,

    /// Contact's nickname.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nickname: Option<String>,

    /// Birthday in YYYY-MM-DD format.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub birthday: Option<String>,

    /// Company name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub company_name: Option<String>,

    /// Job title.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub job_title: Option<String>,

    /// Manager's name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub manager_name: Option<String>,

    /// Office location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub office_location: Option<String>,

    /// Notes about the contact.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub notes: Option<String>,

    /// URL to contact's picture.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub picture_url: Option<String>,

    /// Base64-encoded contact picture.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub picture: Option<String>,

    /// List of email addresses.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub emails: Option<Vec<ContactEmail>>,

    /// List of phone numbers.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub phone_numbers: Option<Vec<ContactPhone>>,

    /// List of physical addresses.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub physical_addresses: Option<Vec<ContactAddress>>,

    /// List of web pages.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub web_pages: Option<Vec<ContactWebPage>>,

    /// List of groups this contact belongs to.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub groups: Option<Vec<ContactGroup>>,
}

impl CreateContactRequest {
    /// Create a builder for CreateContactRequest.
    pub fn builder() -> CreateContactRequestBuilder {
        CreateContactRequestBuilder::default()
    }
}

/// Builder for CreateContactRequest.
#[derive(Debug, Clone, Default)]
pub struct CreateContactRequestBuilder {
    given_name: Option<String>,
    middle_name: Option<String>,
    family_name: Option<String>,
    suffix: Option<String>,
    nickname: Option<String>,
    birthday: Option<String>,
    company_name: Option<String>,
    job_title: Option<String>,
    manager_name: Option<String>,
    office_location: Option<String>,
    notes: Option<String>,
    picture_url: Option<String>,
    picture: Option<String>,
    emails: Option<Vec<ContactEmail>>,
    phone_numbers: Option<Vec<ContactPhone>>,
    physical_addresses: Option<Vec<ContactAddress>>,
    web_pages: Option<Vec<ContactWebPage>>,
    groups: Option<Vec<ContactGroup>>,
}

impl CreateContactRequestBuilder {
    /// Set given name.
    pub fn given_name(mut self, name: impl Into<String>) -> Self {
        self.given_name = Some(name.into());
        self
    }

    /// Set middle name.
    pub fn middle_name(mut self, name: impl Into<String>) -> Self {
        self.middle_name = Some(name.into());
        self
    }

    /// Set family name.
    pub fn family_name(mut self, name: impl Into<String>) -> Self {
        self.family_name = Some(name.into());
        self
    }

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

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

    /// Set birthday (YYYY-MM-DD format).
    pub fn birthday(mut self, birthday: impl Into<String>) -> Self {
        self.birthday = Some(birthday.into());
        self
    }

    /// Set company name.
    pub fn company_name(mut self, name: impl Into<String>) -> Self {
        self.company_name = Some(name.into());
        self
    }

    /// Set job title.
    pub fn job_title(mut self, title: impl Into<String>) -> Self {
        self.job_title = Some(title.into());
        self
    }

    /// Set manager name.
    pub fn manager_name(mut self, name: impl Into<String>) -> Self {
        self.manager_name = Some(name.into());
        self
    }

    /// Set office location.
    pub fn office_location(mut self, location: impl Into<String>) -> Self {
        self.office_location = Some(location.into());
        self
    }

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

    /// Set picture URL.
    pub fn picture_url(mut self, url: impl Into<String>) -> Self {
        self.picture_url = Some(url.into());
        self
    }

    /// Set picture (base64-encoded).
    pub fn picture(mut self, picture: impl Into<String>) -> Self {
        self.picture = Some(picture.into());
        self
    }

    /// Set email addresses.
    pub fn emails(mut self, emails: Vec<ContactEmail>) -> Self {
        self.emails = Some(emails);
        self
    }

    /// Set phone numbers.
    pub fn phone_numbers(mut self, phones: Vec<ContactPhone>) -> Self {
        self.phone_numbers = Some(phones);
        self
    }

    /// Set physical addresses.
    pub fn physical_addresses(mut self, addresses: Vec<ContactAddress>) -> Self {
        self.physical_addresses = Some(addresses);
        self
    }

    /// Set web pages.
    pub fn web_pages(mut self, pages: Vec<ContactWebPage>) -> Self {
        self.web_pages = Some(pages);
        self
    }

    /// Set groups.
    pub fn groups(mut self, groups: Vec<ContactGroup>) -> Self {
        self.groups = Some(groups);
        self
    }

    /// Build the CreateContactRequest.
    pub fn build(self) -> CreateContactRequest {
        CreateContactRequest {
            given_name: self.given_name,
            middle_name: self.middle_name,
            family_name: self.family_name,
            suffix: self.suffix,
            nickname: self.nickname,
            birthday: self.birthday,
            company_name: self.company_name,
            job_title: self.job_title,
            manager_name: self.manager_name,
            office_location: self.office_location,
            notes: self.notes,
            picture_url: self.picture_url,
            picture: self.picture,
            emails: self.emails,
            phone_numbers: self.phone_numbers,
            physical_addresses: self.physical_addresses,
            web_pages: self.web_pages,
            groups: self.groups,
        }
    }
}

/// Request to update a contact.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct UpdateContactRequest {
    /// Update given name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub given_name: Option<String>,

    /// Update middle name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub middle_name: Option<String>,

    /// Update family name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub family_name: Option<String>,

    /// Update suffix.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub suffix: Option<String>,

    /// Update nickname.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nickname: Option<String>,

    /// Update birthday.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub birthday: Option<String>,

    /// Update company name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub company_name: Option<String>,

    /// Update job title.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub job_title: Option<String>,

    /// Update manager name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub manager_name: Option<String>,

    /// Update office location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub office_location: Option<String>,

    /// Update notes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub notes: Option<String>,

    /// Update picture URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub picture_url: Option<String>,

    /// Update picture.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub picture: Option<String>,

    /// Update email addresses.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub emails: Option<Vec<ContactEmail>>,

    /// Update phone numbers.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub phone_numbers: Option<Vec<ContactPhone>>,

    /// Update physical addresses.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub physical_addresses: Option<Vec<ContactAddress>>,

    /// Update web pages.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub web_pages: Option<Vec<ContactWebPage>>,

    /// Update groups.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub groups: Option<Vec<ContactGroup>>,
}

impl UpdateContactRequest {
    /// Create a builder for UpdateContactRequest.
    pub fn builder() -> UpdateContactRequestBuilder {
        UpdateContactRequestBuilder::default()
    }
}

/// Builder for UpdateContactRequest.
#[derive(Debug, Clone, Default)]
pub struct UpdateContactRequestBuilder {
    given_name: Option<String>,
    middle_name: Option<String>,
    family_name: Option<String>,
    suffix: Option<String>,
    nickname: Option<String>,
    birthday: Option<String>,
    company_name: Option<String>,
    job_title: Option<String>,
    manager_name: Option<String>,
    office_location: Option<String>,
    notes: Option<String>,
    picture_url: Option<String>,
    picture: Option<String>,
    emails: Option<Vec<ContactEmail>>,
    phone_numbers: Option<Vec<ContactPhone>>,
    physical_addresses: Option<Vec<ContactAddress>>,
    web_pages: Option<Vec<ContactWebPage>>,
    groups: Option<Vec<ContactGroup>>,
}

impl UpdateContactRequestBuilder {
    /// Set given name.
    pub fn given_name(mut self, name: impl Into<String>) -> Self {
        self.given_name = Some(name.into());
        self
    }

    /// Set middle name.
    pub fn middle_name(mut self, name: impl Into<String>) -> Self {
        self.middle_name = Some(name.into());
        self
    }

    /// Set family name.
    pub fn family_name(mut self, name: impl Into<String>) -> Self {
        self.family_name = Some(name.into());
        self
    }

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

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

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

    /// Set company name.
    pub fn company_name(mut self, name: impl Into<String>) -> Self {
        self.company_name = Some(name.into());
        self
    }

    /// Set job title.
    pub fn job_title(mut self, title: impl Into<String>) -> Self {
        self.job_title = Some(title.into());
        self
    }

    /// Set manager name.
    pub fn manager_name(mut self, name: impl Into<String>) -> Self {
        self.manager_name = Some(name.into());
        self
    }

    /// Set office location.
    pub fn office_location(mut self, location: impl Into<String>) -> Self {
        self.office_location = Some(location.into());
        self
    }

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

    /// Set picture URL.
    pub fn picture_url(mut self, url: impl Into<String>) -> Self {
        self.picture_url = Some(url.into());
        self
    }

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

    /// Set emails.
    pub fn emails(mut self, emails: Vec<ContactEmail>) -> Self {
        self.emails = Some(emails);
        self
    }

    /// Set phone numbers.
    pub fn phone_numbers(mut self, phones: Vec<ContactPhone>) -> Self {
        self.phone_numbers = Some(phones);
        self
    }

    /// Set physical addresses.
    pub fn physical_addresses(mut self, addresses: Vec<ContactAddress>) -> Self {
        self.physical_addresses = Some(addresses);
        self
    }

    /// Set web pages.
    pub fn web_pages(mut self, pages: Vec<ContactWebPage>) -> Self {
        self.web_pages = Some(pages);
        self
    }

    /// Set groups.
    pub fn groups(mut self, groups: Vec<ContactGroup>) -> Self {
        self.groups = Some(groups);
        self
    }

    /// Build the UpdateContactRequest.
    pub fn build(self) -> UpdateContactRequest {
        UpdateContactRequest {
            given_name: self.given_name,
            middle_name: self.middle_name,
            family_name: self.family_name,
            suffix: self.suffix,
            nickname: self.nickname,
            birthday: self.birthday,
            company_name: self.company_name,
            job_title: self.job_title,
            manager_name: self.manager_name,
            office_location: self.office_location,
            notes: self.notes,
            picture_url: self.picture_url,
            picture: self.picture,
            emails: self.emails,
            phone_numbers: self.phone_numbers,
            physical_addresses: self.physical_addresses,
            web_pages: self.web_pages,
            groups: self.groups,
        }
    }
}

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

    #[test]
    fn test_contact_creation() {
        let contact = Contact {
            id: ContactId::new("contact_123"),
            grant_id: GrantId::new("grant_456"),
            given_name: Some("John".to_string()),
            family_name: Some("Doe".to_string()),
            emails: vec![ContactEmail {
                email_type: Some("work".to_string()),
                email: "john.doe@example.com".to_string(),
            }],
            phone_numbers: vec![],
            physical_addresses: vec![],
            web_pages: vec![],
            groups: vec![],
            middle_name: None,
            suffix: None,
            nickname: None,
            birthday: None,
            company_name: None,
            job_title: None,
            manager_name: None,
            office_location: None,
            notes: None,
            picture_url: None,
            picture: None,
        };

        assert_eq!(contact.id.as_str(), "contact_123");
        assert_eq!(contact.given_name.as_ref().unwrap(), "John");
        assert_eq!(contact.family_name.as_ref().unwrap(), "Doe");
        assert_eq!(contact.emails.len(), 1);
    }

    #[test]
    fn test_contact_serialization() {
        let contact = Contact {
            id: ContactId::new("contact_123"),
            grant_id: GrantId::new("grant_456"),
            given_name: Some("Jane".to_string()),
            family_name: Some("Smith".to_string()),
            emails: vec![],
            phone_numbers: vec![],
            physical_addresses: vec![],
            web_pages: vec![],
            groups: vec![],
            middle_name: None,
            suffix: None,
            nickname: None,
            birthday: None,
            company_name: Some("Acme Corp".to_string()),
            job_title: Some("Engineer".to_string()),
            manager_name: None,
            office_location: None,
            notes: None,
            picture_url: None,
            picture: None,
        };

        let json = serde_json::to_string(&contact).unwrap();
        assert!(json.contains("contact_123"));
        assert!(json.contains("Jane"));
        assert!(json.contains("Acme Corp"));
    }

    #[test]
    fn test_contact_deserialization() {
        let json = r#"{
            "id": "contact_123",
            "grant_id": "grant_456",
            "given_name": "Bob",
            "family_name": "Johnson",
            "company_name": "Tech Inc",
            "emails": [],
            "phone_numbers": [],
            "physical_addresses": [],
            "web_pages": [],
            "groups": []
        }"#;

        let contact: Contact = serde_json::from_str(json).unwrap();
        assert_eq!(contact.id.as_str(), "contact_123");
        assert_eq!(contact.given_name.as_ref().unwrap(), "Bob");
        assert_eq!(contact.company_name.as_ref().unwrap(), "Tech Inc");
    }

    #[test]
    fn test_create_contact_request_builder() {
        let request = CreateContactRequest::builder()
            .given_name("Alice")
            .family_name("Williams")
            .company_name("Example LLC")
            .job_title("Manager")
            .build();

        assert_eq!(request.given_name.as_ref().unwrap(), "Alice");
        assert_eq!(request.family_name.as_ref().unwrap(), "Williams");
        assert_eq!(request.company_name.as_ref().unwrap(), "Example LLC");
        assert_eq!(request.job_title.as_ref().unwrap(), "Manager");
    }

    #[test]
    fn test_update_contact_request_builder() {
        let update = UpdateContactRequest::builder()
            .given_name("Updated Name")
            .job_title("Senior Engineer")
            .build();

        assert_eq!(update.given_name.as_ref().unwrap(), "Updated Name");
        assert_eq!(update.job_title.as_ref().unwrap(), "Senior Engineer");
        assert!(update.company_name.is_none());
    }

    #[test]
    fn test_contact_email() {
        let email = ContactEmail {
            email_type: Some("work".to_string()),
            email: "test@example.com".to_string(),
        };

        assert_eq!(email.email_type.as_ref().unwrap(), "work");
        assert_eq!(email.email, "test@example.com");
    }

    #[test]
    fn test_contact_phone() {
        let phone = ContactPhone {
            phone_type: Some("mobile".to_string()),
            number: "+1234567890".to_string(),
        };

        assert_eq!(phone.phone_type.as_ref().unwrap(), "mobile");
        assert_eq!(phone.number, "+1234567890");
    }

    #[test]
    fn test_contact_address() {
        let address = ContactAddress {
            address_type: Some("home".to_string()),
            street_address: Some("123 Main St".to_string()),
            city: Some("Springfield".to_string()),
            state: Some("IL".to_string()),
            postal_code: Some("62701".to_string()),
            country: Some("USA".to_string()),
        };

        assert_eq!(address.address_type.as_ref().unwrap(), "home");
        assert_eq!(address.city.as_ref().unwrap(), "Springfield");
    }
}