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
use crate::errors::Result;
use crate::types::*;
use uuid::Uuid;

/// Represents a filter of user chats
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ChatFilter {
    #[doc(hidden)]
    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
    extra: Option<String>,
    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
    client_id: Option<i32>,
    /// The title of the filter; 1-12 characters without line feeds

    #[serde(default)]
    title: String,
    /// The chosen icon name for short filter representation. If non-empty, must be one of "All", "Unread", "Unmuted", "Bots", "Channels", "Groups", "Private", "Custom", "Setup", "Cat", "Crown", "Favorite", "Flower", "Game", "Home", "Love", "Mask", "Party", "Sport", "Study", "Trade", "Travel", "Work". If empty, use getChatFilterDefaultIconName to get default icon name for the filter

    #[serde(default)]
    icon_name: String,
    /// The chat identifiers of pinned chats in the filtered chat list

    #[serde(default)]
    pinned_chat_ids: Vec<i64>,
    /// The chat identifiers of always included chats in the filtered chat list

    #[serde(default)]
    included_chat_ids: Vec<i64>,
    /// The chat identifiers of always excluded chats in the filtered chat list

    #[serde(default)]
    excluded_chat_ids: Vec<i64>,
    /// True, if muted chats need to be excluded

    #[serde(default)]
    exclude_muted: bool,
    /// True, if read chats need to be excluded

    #[serde(default)]
    exclude_read: bool,
    /// True, if archived chats need to be excluded

    #[serde(default)]
    exclude_archived: bool,
    /// True, if contacts need to be included

    #[serde(default)]
    include_contacts: bool,
    /// True, if non-contact users need to be included

    #[serde(default)]
    include_non_contacts: bool,
    /// True, if bots need to be included

    #[serde(default)]
    include_bots: bool,
    /// True, if basic groups and supergroups need to be included

    #[serde(default)]
    include_groups: bool,
    /// True, if channels need to be included

    #[serde(default)]
    include_channels: bool,
}

impl RObject for ChatFilter {
    #[doc(hidden)]
    fn extra(&self) -> Option<&str> {
        self.extra.as_deref()
    }
    #[doc(hidden)]
    fn client_id(&self) -> Option<i32> {
        self.client_id
    }
}

impl ChatFilter {
    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
        Ok(serde_json::from_str(json.as_ref())?)
    }
    pub fn builder() -> ChatFilterBuilder {
        let mut inner = ChatFilter::default();
        inner.extra = Some(Uuid::new_v4().to_string());

        ChatFilterBuilder { inner }
    }

    pub fn title(&self) -> &String {
        &self.title
    }

    pub fn icon_name(&self) -> &String {
        &self.icon_name
    }

    pub fn pinned_chat_ids(&self) -> &Vec<i64> {
        &self.pinned_chat_ids
    }

    pub fn included_chat_ids(&self) -> &Vec<i64> {
        &self.included_chat_ids
    }

    pub fn excluded_chat_ids(&self) -> &Vec<i64> {
        &self.excluded_chat_ids
    }

    pub fn exclude_muted(&self) -> bool {
        self.exclude_muted
    }

    pub fn exclude_read(&self) -> bool {
        self.exclude_read
    }

    pub fn exclude_archived(&self) -> bool {
        self.exclude_archived
    }

    pub fn include_contacts(&self) -> bool {
        self.include_contacts
    }

    pub fn include_non_contacts(&self) -> bool {
        self.include_non_contacts
    }

    pub fn include_bots(&self) -> bool {
        self.include_bots
    }

    pub fn include_groups(&self) -> bool {
        self.include_groups
    }

    pub fn include_channels(&self) -> bool {
        self.include_channels
    }
}

#[doc(hidden)]
pub struct ChatFilterBuilder {
    inner: ChatFilter,
}

#[deprecated]
pub type RTDChatFilterBuilder = ChatFilterBuilder;

impl ChatFilterBuilder {
    pub fn build(&self) -> ChatFilter {
        self.inner.clone()
    }

    pub fn title<T: AsRef<str>>(&mut self, title: T) -> &mut Self {
        self.inner.title = title.as_ref().to_string();
        self
    }

    pub fn icon_name<T: AsRef<str>>(&mut self, icon_name: T) -> &mut Self {
        self.inner.icon_name = icon_name.as_ref().to_string();
        self
    }

    pub fn pinned_chat_ids(&mut self, pinned_chat_ids: Vec<i64>) -> &mut Self {
        self.inner.pinned_chat_ids = pinned_chat_ids;
        self
    }

    pub fn included_chat_ids(&mut self, included_chat_ids: Vec<i64>) -> &mut Self {
        self.inner.included_chat_ids = included_chat_ids;
        self
    }

    pub fn excluded_chat_ids(&mut self, excluded_chat_ids: Vec<i64>) -> &mut Self {
        self.inner.excluded_chat_ids = excluded_chat_ids;
        self
    }

    pub fn exclude_muted(&mut self, exclude_muted: bool) -> &mut Self {
        self.inner.exclude_muted = exclude_muted;
        self
    }

    pub fn exclude_read(&mut self, exclude_read: bool) -> &mut Self {
        self.inner.exclude_read = exclude_read;
        self
    }

    pub fn exclude_archived(&mut self, exclude_archived: bool) -> &mut Self {
        self.inner.exclude_archived = exclude_archived;
        self
    }

    pub fn include_contacts(&mut self, include_contacts: bool) -> &mut Self {
        self.inner.include_contacts = include_contacts;
        self
    }

    pub fn include_non_contacts(&mut self, include_non_contacts: bool) -> &mut Self {
        self.inner.include_non_contacts = include_non_contacts;
        self
    }

    pub fn include_bots(&mut self, include_bots: bool) -> &mut Self {
        self.inner.include_bots = include_bots;
        self
    }

    pub fn include_groups(&mut self, include_groups: bool) -> &mut Self {
        self.inner.include_groups = include_groups;
        self
    }

    pub fn include_channels(&mut self, include_channels: bool) -> &mut Self {
        self.inner.include_channels = include_channels;
        self
    }
}

impl AsRef<ChatFilter> for ChatFilter {
    fn as_ref(&self) -> &ChatFilter {
        self
    }
}

impl AsRef<ChatFilter> for ChatFilterBuilder {
    fn as_ref(&self) -> &ChatFilter {
        &self.inner
    }
}