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
use crate::scheduling::RoundRobinAlgorithm;
use crate::{
shared::entity::{Entity, ID},
Meta, Metadata,
};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "variant", content = "id")]
pub enum TimePlan {
Calendar(ID),
Schedule(ID),
Empty,
}
#[derive(Clone, Debug, Serialize)]
pub struct ServiceResource {
pub user_id: ID,
pub service_id: ID,
pub availability: TimePlan,
pub buffer_after: i64,
pub buffer_before: i64,
pub closest_booking_time: i64,
pub furthest_booking_time: Option<i64>,
}
impl ServiceResource {
pub fn new(user_id: ID, service_id: ID, availability: TimePlan) -> Self {
Self {
service_id,
user_id,
availability,
buffer_after: 0,
buffer_before: 0,
closest_booking_time: 0,
furthest_booking_time: None,
}
}
pub fn set_availability(&mut self, availability: TimePlan) {
self.availability = availability;
}
fn valid_buffer(&self, buffer: i64) -> bool {
let min_buffer = 0;
let max_buffer = 60 * 12;
if buffer < min_buffer || buffer > max_buffer {
return false;
}
true
}
pub fn set_buffer_after(&mut self, buffer: i64) -> bool {
if self.valid_buffer(buffer) {
self.buffer_after = buffer;
return true;
}
false
}
pub fn set_buffer_before(&mut self, buffer: i64) -> bool {
if self.valid_buffer(buffer) {
self.buffer_before = buffer;
return true;
}
false
}
pub fn get_schedule_id(&self) -> Option<ID> {
match &self.availability {
TimePlan::Schedule(id) => Some(id.clone()),
_ => None,
}
}
}
impl Entity<String> for ServiceResource {
fn id(&self) -> String {
format!("{}#{}", self.service_id, self.user_id)
}
}
#[derive(Clone, Debug)]
pub struct Service {
pub id: ID,
pub account_id: ID,
pub multi_person: ServiceMultiPersonOptions,
pub metadata: Metadata,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "variant", content = "data", rename_all = "camelCase")]
pub enum ServiceMultiPersonOptions {
RoundRobinAlgorithm(RoundRobinAlgorithm),
Collective,
Group(usize),
}
impl Default for ServiceMultiPersonOptions {
fn default() -> Self {
Self::RoundRobinAlgorithm(RoundRobinAlgorithm::default())
}
}
impl Entity<ID> for Service {
fn id(&self) -> ID {
self.id.clone()
}
}
impl Meta<ID> for Service {
fn metadata(&self) -> &Metadata {
&self.metadata
}
fn account_id(&self) -> &ID {
&self.account_id
}
}
impl Service {
pub fn new(account_id: ID) -> Self {
Self {
id: Default::default(),
account_id,
multi_person: Default::default(),
metadata: Default::default(),
}
}
}
#[derive(Debug)]
pub struct ServiceWithUsers {
pub id: ID,
pub account_id: ID,
pub users: Vec<ServiceResource>,
pub multi_person: ServiceMultiPersonOptions,
pub metadata: Metadata,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "provider", content = "id")]
pub enum BusyCalendar {
Google(String),
Outlook(String),
Nettu(ID),
}