1use super::{Channel, File, RE_COLOUR};
2
3use revolt_permissions::{Override, OverrideField};
4use std::collections::HashMap;
5
6#[cfg(feature = "validator")]
7use validator::Validate;
8
9#[cfg(feature = "rocket")]
10use rocket::FromForm;
11
12auto_derived_partial!(
13 pub struct Server {
15 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
17 pub id: String,
18 pub owner: String,
20
21 pub name: String,
23 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
25 pub description: Option<String>,
26
27 pub channels: Vec<String>,
30 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
32 pub categories: Option<Vec<Category>>,
33 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
35 pub system_messages: Option<SystemMessageChannels>,
36
37 #[cfg_attr(
39 feature = "serde",
40 serde(
41 default = "HashMap::<String, Role>::new",
42 skip_serializing_if = "HashMap::<String, Role>::is_empty"
43 )
44 )]
45 pub roles: HashMap<String, Role>,
46 pub default_permissions: i64,
48
49 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
51 pub icon: Option<File>,
52 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
54 pub banner: Option<File>,
55
56 #[cfg_attr(
58 feature = "serde",
59 serde(skip_serializing_if = "crate::if_zero_u32", default)
60 )]
61 pub flags: u32,
62
63 #[cfg_attr(
65 feature = "serde",
66 serde(skip_serializing_if = "crate::if_false", default)
67 )]
68 pub nsfw: bool,
69 #[cfg_attr(
71 feature = "serde",
72 serde(skip_serializing_if = "crate::if_false", default)
73 )]
74 pub analytics: bool,
75 #[cfg_attr(
77 feature = "serde",
78 serde(skip_serializing_if = "crate::if_false", default)
79 )]
80 pub discoverable: bool,
81 },
82 "PartialServer"
83);
84
85auto_derived_partial!(
86 pub struct Role {
88 #[cfg_attr(feature = "serde", serde(rename = "_id"))]
90 pub id: String,
91 pub name: String,
93 pub permissions: OverrideField,
95 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
99 pub colour: Option<String>,
100 #[cfg_attr(
102 feature = "serde",
103 serde(skip_serializing_if = "crate::if_false", default)
104 )]
105 pub hoist: bool,
106 #[cfg_attr(feature = "serde", serde(default))]
108 pub rank: i64,
109 },
110 "PartialRole"
111);
112
113auto_derived!(
114 pub enum FieldsServer {
116 Description,
117 Categories,
118 SystemMessages,
119 Icon,
120 Banner,
121 }
122
123 pub enum FieldsRole {
125 Colour,
126 }
127
128 #[cfg_attr(feature = "validator", derive(Validate))]
130 pub struct Category {
131 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
133 pub id: String,
134 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
136 pub title: String,
137 pub channels: Vec<String>,
139 }
140
141 pub struct SystemMessageChannels {
143 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
145 pub user_joined: Option<String>,
146 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
148 pub user_left: Option<String>,
149 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
151 pub user_kicked: Option<String>,
152 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
154 pub user_banned: Option<String>,
155 }
156
157 #[derive(Default)]
159 #[cfg_attr(feature = "validator", derive(Validate))]
160 pub struct DataCreateServer {
161 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
163 pub name: String,
164 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
166 pub description: Option<String>,
167 #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
169 pub nsfw: Option<bool>,
170 }
171
172 #[cfg_attr(feature = "validator", derive(Validate))]
174 pub struct DataCreateRole {
175 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
177 pub name: String,
178 pub rank: Option<i64>,
184 }
185
186 pub struct NewRoleResponse {
189 pub id: String,
191 pub role: Role,
193 }
194
195 pub struct CreateServerLegacyResponse {
197 pub server: Server,
199 pub channels: Vec<Channel>,
201 }
202
203 #[cfg_attr(feature = "rocket", derive(FromForm))]
205 pub struct OptionsFetchServer {
206 pub include_channels: Option<bool>,
208 }
209
210 #[serde(untagged)]
212 pub enum FetchServerResponse {
213 JustServer(Server),
214 ServerWithChannels {
215 #[serde(flatten)]
216 server: Server,
217 channels: Vec<Channel>,
218 },
219 }
220
221 #[cfg_attr(feature = "validator", derive(Validate))]
223 pub struct DataEditServer {
224 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
226 pub name: Option<String>,
227 #[cfg_attr(feature = "validator", validate(length(min = 0, max = 1024)))]
229 pub description: Option<String>,
230
231 pub icon: Option<String>,
233 pub banner: Option<String>,
235
236 #[cfg_attr(feature = "validator", validate)]
238 pub categories: Option<Vec<Category>>,
239 pub system_messages: Option<SystemMessageChannels>,
241
242 #[cfg_attr(feature = "validator", serde(skip_serializing_if = "Option::is_none"))]
244 pub flags: Option<i32>,
245
246 pub discoverable: Option<bool>,
250 pub analytics: Option<bool>,
254
255 #[cfg_attr(feature = "serde", serde(default))]
257 pub remove: Vec<FieldsServer>,
258 }
259
260 #[cfg_attr(feature = "validator", derive(Validate))]
262 pub struct DataEditRole {
263 #[cfg_attr(feature = "validator", validate(length(min = 1, max = 32)))]
265 pub name: Option<String>,
266 #[cfg_attr(
268 feature = "validator",
269 validate(length(min = 1, max = 128), regex = "RE_COLOUR")
270 )]
271 pub colour: Option<String>,
272 pub hoist: Option<bool>,
274 pub rank: Option<i64>,
278 #[cfg_attr(feature = "serde", serde(default))]
280 pub remove: Vec<FieldsRole>,
281 }
282
283 pub struct DataSetServerRolePermission {
285 pub permissions: Override,
287 }
288
289 #[cfg_attr(feature = "rocket", derive(FromForm))]
291 pub struct OptionsServerDelete {
292 pub leave_silently: Option<bool>,
294 }
295
296 pub struct DataEditRoleRanks {
298 pub ranks: Vec<String>,
299 }
300);