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
//! Scheduler types for the Nylas API v3.
//!
//! Scheduler allows users to create booking pages and manage meeting scheduling.

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

use crate::{CalendarId, SchedulerBookingId, SchedulerConfigId, SchedulerSessionId};

/// Scheduler configuration.
///
/// Defines the settings for a scheduling page.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SchedulerConfig {
    /// Unique identifier for the configuration.
    pub id: SchedulerConfigId,

    /// Name of the configuration.
    pub name: String,

    /// Slug used in the booking URL.
    pub slug: String,

    /// Event title template.
    pub event_title: String,

    /// Event description.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub event_description: Option<String>,

    /// Event duration in minutes.
    pub duration_minutes: u32,

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

    /// Calendar IDs to check availability against.
    pub calendar_ids: Vec<CalendarId>,

    /// Availability settings.
    pub availability: AvailabilitySettings,

    /// Booking settings.
    pub booking: BookingSettings,

    /// Whether this configuration is active.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub active: Option<bool>,

    /// Unix timestamp when created.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<i64>,

    /// Unix timestamp when last modified.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub modified_at: Option<i64>,
}

/// Availability settings for scheduler.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AvailabilitySettings {
    /// Days of the week available for booking.
    pub days: Vec<DayOfWeek>,

    /// Start time for availability (e.g., "09:00").
    pub start_time: String,

    /// End time for availability (e.g., "17:00").
    pub end_time: String,

    /// Timezone for availability.
    pub timezone: String,

    /// Minimum notice period in minutes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_notice_minutes: Option<u32>,

    /// Buffer time between meetings in minutes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub buffer_minutes: Option<u32>,
}

/// Day of the week for availability.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum DayOfWeek {
    /// Monday
    Monday,
    /// Tuesday
    Tuesday,
    /// Wednesday
    Wednesday,
    /// Thursday
    Thursday,
    /// Friday
    Friday,
    /// Saturday
    Saturday,
    /// Sunday
    Sunday,
}

/// Booking settings for scheduler.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BookingSettings {
    /// Confirmation message shown after booking.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub confirmation_message: Option<String>,

    /// Confirmation redirect URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub confirmation_redirect_url: Option<String>,

    /// Required fields for booking form.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub required_fields: Option<Vec<String>>,

    /// Custom fields for booking form.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_fields: Option<Vec<CustomField>>,

    /// Whether to send confirmation emails.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub send_confirmation_email: Option<bool>,

    /// Whether to send reminder emails.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub send_reminder_email: Option<bool>,

    /// Reminder time in minutes before the meeting.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reminder_minutes: Option<u32>,
}

/// Custom field for booking form.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CustomField {
    /// Field name.
    pub name: String,

    /// Field label shown to users.
    pub label: String,

    /// Field type.
    #[serde(rename = "type")]
    pub field_type: CustomFieldType,

    /// Whether this field is required.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub required: Option<bool>,

    /// Options for select/radio fields.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub options: Option<Vec<String>>,
}

/// Type of custom field.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum CustomFieldType {
    /// Text input
    Text,
    /// Email input
    Email,
    /// Phone number input
    Phone,
    /// Select dropdown
    Select,
    /// Radio buttons
    Radio,
    /// Checkbox
    Checkbox,
    /// Text area
    Textarea,
}

/// Supported locales for scheduler UI.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Locale {
    /// English
    En,
    /// Spanish
    Es,
    /// French
    Fr,
    /// German
    De,
    /// Japanese
    Ja,
    /// Chinese (Simplified)
    #[serde(rename = "zh")]
    ZhCn,
    /// Korean (NEW in 2024)
    Ko,
}

/// Request to create a scheduler configuration.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CreateSchedulerConfigRequest {
    /// Name of the configuration.
    pub name: String,

    /// Slug used in the booking URL.
    pub slug: String,

    /// Event title template.
    pub event_title: String,

    /// Event description.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub event_description: Option<String>,

    /// Event duration in minutes.
    pub duration_minutes: u32,

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

    /// Calendar IDs to check availability against.
    pub calendar_ids: Vec<String>,

    /// Availability settings.
    pub availability: AvailabilitySettings,

    /// Booking settings.
    pub booking: BookingSettings,
}

/// Request to update a scheduler configuration.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct UpdateSchedulerConfigRequest {
    /// Name of the configuration.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,

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

    /// Event description.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub event_description: Option<String>,

    /// Event duration in minutes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration_minutes: Option<u32>,

    /// Whether this configuration is active.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub active: Option<bool>,
}

/// Scheduler session.
///
/// Represents an active scheduling session for a guest.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SchedulerSession {
    /// Unique identifier for the session.
    pub id: SchedulerSessionId,

    /// Configuration ID this session belongs to.
    pub config_id: SchedulerConfigId,

    /// Guest email address.
    pub email: String,

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

    /// Session expiry timestamp.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expires_at: Option<i64>,

    /// Additional session data.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<HashMap<String, String>>,
}

/// Request to create a scheduler session.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CreateSchedulerSessionRequest {
    /// Configuration ID to create session for.
    pub config_id: String,

    /// Guest email address.
    pub email: String,

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

    /// Additional session metadata.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<HashMap<String, String>>,
}

/// Scheduler booking.
///
/// Represents a confirmed booking created through the scheduler.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SchedulerBooking {
    /// Unique identifier for the booking.
    pub id: SchedulerBookingId,

    /// Configuration ID used for this booking.
    pub config_id: SchedulerConfigId,

    /// Session ID if created through a session.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub session_id: Option<SchedulerSessionId>,

    /// Event ID created for this booking.
    pub event_id: String,

    /// Guest email address.
    pub email: String,

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

    /// Booking start time (Unix timestamp).
    pub start_time: i64,

    /// Booking end time (Unix timestamp).
    pub end_time: i64,

    /// Timezone for the booking.
    pub timezone: String,

    /// Booking status.
    pub status: BookingStatus,

    /// Custom field responses.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_fields: Option<HashMap<String, String>>,

    /// Unix timestamp when created.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<i64>,
}

/// Status of a booking.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum BookingStatus {
    /// Booking is confirmed
    Confirmed,
    /// Booking was cancelled
    Cancelled,
    /// Booking is pending
    Pending,
}

/// Request to create a scheduler booking.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CreateSchedulerBookingRequest {
    /// Configuration ID to book against.
    pub config_id: String,

    /// Session ID if using a session.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub session_id: Option<String>,

    /// Guest email address.
    pub email: String,

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

    /// Booking start time (Unix timestamp).
    pub start_time: i64,

    /// Timezone for the booking.
    pub timezone: String,

    /// Custom field responses.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom_fields: Option<HashMap<String, String>>,
}

/// Request to cancel a scheduler booking.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CancelSchedulerBookingRequest {
    /// Reason for cancellation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason: Option<String>,
}

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

    #[test]
    fn test_scheduler_config_id() {
        let id = SchedulerConfigId::new("config_123");
        assert_eq!(id.as_str(), "config_123");
    }

    #[test]
    fn test_day_of_week_serialization() {
        let day = DayOfWeek::Monday;
        let json = serde_json::to_string(&day).unwrap();
        assert_eq!(json, "\"monday\"");

        let deserialized: DayOfWeek = serde_json::from_str(&json).unwrap();
        assert_eq!(day, deserialized);
    }

    #[test]
    fn test_custom_field_type_serialization() {
        let field_type = CustomFieldType::Email;
        let json = serde_json::to_string(&field_type).unwrap();
        assert_eq!(json, "\"email\"");

        let deserialized: CustomFieldType = serde_json::from_str(&json).unwrap();
        assert_eq!(field_type, deserialized);
    }

    #[test]
    fn test_booking_status_serialization() {
        let status = BookingStatus::Confirmed;
        let json = serde_json::to_string(&status).unwrap();
        assert_eq!(json, "\"confirmed\"");

        let deserialized: BookingStatus = serde_json::from_str(&json).unwrap();
        assert_eq!(status, deserialized);
    }

    #[test]
    fn test_create_scheduler_booking_request() {
        let request = CreateSchedulerBookingRequest {
            config_id: "config_123".to_string(),
            session_id: Some("session_456".to_string()),
            email: "guest@example.com".to_string(),
            name: Some("Guest Name".to_string()),
            start_time: 1735689600,
            timezone: "America/New_York".to_string(),
            custom_fields: None,
        };

        let json = serde_json::to_string(&request).unwrap();
        let deserialized: CreateSchedulerBookingRequest = serde_json::from_str(&json).unwrap();
        assert_eq!(request, deserialized);
    }

    #[test]
    fn test_korean_locale() {
        let locale = Locale::Ko;
        let json = serde_json::to_string(&locale).unwrap();
        assert_eq!(json, "\"ko\"");
    }

    #[test]
    fn test_korean_locale_deserialization() {
        let json = "\"ko\"";
        let locale: Locale = serde_json::from_str(json).unwrap();
        assert_eq!(locale, Locale::Ko);
    }
}