Skip to main content

ibridge_server/
contacts_dto.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Contacts tool arguments and structured results.
4
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8fn default_page_limit() -> u32 {
9    25
10}
11
12/// Arguments for `contacts_search`.
13#[derive(Debug, Default, Deserialize, JsonSchema)]
14pub struct SearchContactsParams {
15    /// A name, an email address or a phone number, or part of one.
16    pub query: String,
17    /// Most contacts to return. Omitted means 25. More than 100 is rejected.
18    #[serde(default = "default_page_limit")]
19    pub limit: u32,
20    /// Also return groups, to find the id of a group for `contacts_set_group_membership`.
21    #[serde(default)]
22    pub include_groups: Option<bool>,
23}
24
25/// Arguments for `contacts_create`.
26#[derive(Debug, Default, Deserialize, JsonSchema)]
27pub struct CreateContactParams {
28    /// Full name, such as `Ada Lovelace`.
29    pub full_name: String,
30    /// Email addresses.
31    #[serde(default)]
32    pub emails: Vec<String>,
33    /// Phone numbers.
34    #[serde(default)]
35    pub phones: Vec<String>,
36}
37
38/// Arguments for `contacts_update`.
39#[derive(Debug, Default, Deserialize, JsonSchema)]
40pub struct UpdateContactParams {
41    /// Opaque contact id.
42    pub id: String,
43    /// The `etag` from the last read. A different one means the contact changed.
44    pub etag: String,
45    /// New full name. Omit to keep it.
46    #[serde(default)]
47    pub full_name: Option<String>,
48    /// The full list of email addresses the contact should have. Omit to keep them.
49    #[serde(default)]
50    pub emails: Option<Vec<String>>,
51    /// The full list of phone numbers the contact should have. Omit to keep them.
52    #[serde(default)]
53    pub phones: Option<Vec<String>>,
54}
55
56/// Arguments for `contacts_set_group_membership`.
57#[derive(Debug, Default, Deserialize, JsonSchema)]
58pub struct SetGroupMembershipParams {
59    /// Id of an existing group, from `contacts_search` with `include_groups`
60    /// or from a contact's `groups`.
61    pub group: String,
62    /// Id of the contact to add or remove.
63    pub contact: String,
64    /// `add` or `remove`.
65    pub action: String,
66}
67
68#[derive(Debug, Serialize, JsonSchema)]
69pub(crate) struct LabeledOut {
70    /// As stored on the card.
71    pub(crate) value: String,
72    /// As stored on the card.
73    pub(crate) label: Option<String>,
74}
75
76#[derive(Debug, Serialize, JsonSchema)]
77pub(crate) struct GroupOut {
78    /// Pass as `group` to `contacts_set_group_membership`.
79    pub(crate) id: String,
80    /// As stored on the card.
81    pub(crate) name: String,
82}
83
84#[derive(Debug, Serialize, JsonSchema)]
85pub(crate) struct ContactOut {
86    pub(crate) id: String,
87    pub(crate) etag: String,
88    /// As stored on the card.
89    pub(crate) name: String,
90    pub(crate) emails: Vec<LabeledOut>,
91    pub(crate) phones: Vec<LabeledOut>,
92    /// As stored on the card.
93    pub(crate) organization: Option<String>,
94    /// As stored on the card.
95    pub(crate) note: Option<String>,
96    /// The card is a group, not a person.
97    pub(crate) is_group: bool,
98    /// Groups the contact is in. Only `contacts_get` fills this.
99    pub(crate) groups: Vec<GroupOut>,
100}
101
102#[derive(Debug, Serialize, JsonSchema)]
103pub(crate) struct ContactListOut {
104    pub(crate) contacts: Vec<ContactOut>,
105    /// Cards that could not be read and were skipped.
106    pub(crate) warnings: u32,
107}
108
109#[derive(Debug, Serialize, JsonSchema)]
110pub(crate) struct MembershipOut {
111    pub(crate) updated: bool,
112}