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

use std::fmt::Debug;

/// Describes a fill of a background
pub trait TDBackgroundFill: Debug + RObject {}

/// Describes a fill of a background
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
#[serde(tag = "@type")]
pub enum BackgroundFill {
    #[doc(hidden)]
    #[default]
    _Default,
    /// Describes a freeform gradient fill of a background
    #[serde(rename = "backgroundFillFreeformGradient")]
    FreeformGradient(BackgroundFillFreeformGradient),
    /// Describes a gradient fill of a background
    #[serde(rename = "backgroundFillGradient")]
    Gradient(BackgroundFillGradient),
    /// Describes a solid fill of a background
    #[serde(rename = "backgroundFillSolid")]
    Solid(BackgroundFillSolid),
}

impl RObject for BackgroundFill {
    #[doc(hidden)]
    fn extra(&self) -> Option<&str> {
        match self {
            BackgroundFill::FreeformGradient(t) => t.extra(),
            BackgroundFill::Gradient(t) => t.extra(),
            BackgroundFill::Solid(t) => t.extra(),

            _ => None,
        }
    }
    #[doc(hidden)]
    fn client_id(&self) -> Option<i32> {
        match self {
            BackgroundFill::FreeformGradient(t) => t.client_id(),
            BackgroundFill::Gradient(t) => t.client_id(),
            BackgroundFill::Solid(t) => t.client_id(),

            _ => None,
        }
    }
}

impl BackgroundFill {
    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
        Ok(serde_json::from_str(json.as_ref())?)
    }
    #[doc(hidden)]
    pub fn _is_default(&self) -> bool {
        matches!(self, BackgroundFill::_Default)
    }
}

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

/// Describes a freeform gradient fill of a background
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BackgroundFillFreeformGradient {
    #[doc(hidden)]
    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
    extra: Option<String>,
    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
    client_id: Option<i32>,
    /// A list of 3 or 4 colors of the freeform gradients in the RGB24 format

    #[serde(default)]
    colors: Vec<i32>,
}

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

impl TDBackgroundFill for BackgroundFillFreeformGradient {}

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

        BackgroundFillFreeformGradientBuilder { inner }
    }

    pub fn colors(&self) -> &Vec<i32> {
        &self.colors
    }
}

#[doc(hidden)]
pub struct BackgroundFillFreeformGradientBuilder {
    inner: BackgroundFillFreeformGradient,
}

#[deprecated]
pub type RTDBackgroundFillFreeformGradientBuilder = BackgroundFillFreeformGradientBuilder;

impl BackgroundFillFreeformGradientBuilder {
    pub fn build(&self) -> BackgroundFillFreeformGradient {
        self.inner.clone()
    }

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

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

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

/// Describes a gradient fill of a background
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BackgroundFillGradient {
    #[doc(hidden)]
    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
    extra: Option<String>,
    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
    client_id: Option<i32>,
    /// A top color of the background in the RGB24 format

    #[serde(default)]
    top_color: i32,
    /// A bottom color of the background in the RGB24 format

    #[serde(default)]
    bottom_color: i32,
    /// Clockwise rotation angle of the gradient, in degrees; 0-359. Must be always divisible by 45

    #[serde(default)]
    rotation_angle: i32,
}

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

impl TDBackgroundFill for BackgroundFillGradient {}

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

        BackgroundFillGradientBuilder { inner }
    }

    pub fn top_color(&self) -> i32 {
        self.top_color
    }

    pub fn bottom_color(&self) -> i32 {
        self.bottom_color
    }

    pub fn rotation_angle(&self) -> i32 {
        self.rotation_angle
    }
}

#[doc(hidden)]
pub struct BackgroundFillGradientBuilder {
    inner: BackgroundFillGradient,
}

#[deprecated]
pub type RTDBackgroundFillGradientBuilder = BackgroundFillGradientBuilder;

impl BackgroundFillGradientBuilder {
    pub fn build(&self) -> BackgroundFillGradient {
        self.inner.clone()
    }

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

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

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

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

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

/// Describes a solid fill of a background
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BackgroundFillSolid {
    #[doc(hidden)]
    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
    extra: Option<String>,
    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
    client_id: Option<i32>,
    /// A color of the background in the RGB24 format

    #[serde(default)]
    color: i32,
}

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

impl TDBackgroundFill for BackgroundFillSolid {}

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

        BackgroundFillSolidBuilder { inner }
    }

    pub fn color(&self) -> i32 {
        self.color
    }
}

#[doc(hidden)]
pub struct BackgroundFillSolidBuilder {
    inner: BackgroundFillSolid,
}

#[deprecated]
pub type RTDBackgroundFillSolidBuilder = BackgroundFillSolidBuilder;

impl BackgroundFillSolidBuilder {
    pub fn build(&self) -> BackgroundFillSolid {
        self.inner.clone()
    }

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

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

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