1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6 attachment::Attachment,
7 member::MemberCompositeKey,
8 permission::{OverrideField, Permission},
9};
10
11#[derive(Deserialize, Debug, Clone)]
13pub struct Role {
14 pub name: String,
16 pub permissions: OverrideField,
18 pub colour: Option<String>,
22 #[serde(default)]
24 pub hoist: bool,
25 #[serde(default)]
27 pub rank: i64,
28}
29
30#[derive(Deserialize, Debug, Clone)]
32pub struct NewRole {
33 pub id: String,
35 pub role: Role,
37}
38
39#[derive(Deserialize, Debug, Clone)]
41pub struct PartialRole {
42 pub name: Option<String>,
44 pub permissions: Option<OverrideField>,
46 pub colour: Option<String>,
50 pub hoist: Option<bool>,
52 pub rank: Option<i64>,
54}
55
56#[derive(Serialize, Deserialize, Debug, Clone)]
58pub struct Category {
59 pub id: String,
61 pub title: String,
63 pub channels: Vec<String>,
65}
66
67#[derive(Serialize, Deserialize, Debug, Clone, Default)]
69pub struct SystemMessageChannels {
70 pub user_joined: Option<String>,
72 pub user_left: Option<String>,
74 pub user_kicked: Option<String>,
76 pub user_banned: Option<String>,
78}
79
80bitflags::bitflags! {
81 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
83 pub struct ServerFlags: u64 {
84 const Verified = 1;
85 const Official = 2;
86 }
87}
88crate::impl_serde_bitflags!(ServerFlags);
89
90#[derive(Deserialize, Debug, Clone)]
92pub struct Server {
93 #[serde(rename = "_id")]
95 pub id: String,
96 pub owner: String,
98
99 pub name: String,
101 pub description: Option<String>,
103
104 pub channels: Vec<String>,
107 pub categories: Option<Vec<Category>>,
109 pub system_messages: Option<SystemMessageChannels>,
111
112 #[serde(default = "HashMap::<String, Role>::new")]
114 pub roles: HashMap<String, Role>,
115 pub default_permissions: Permission,
117
118 pub icon: Option<Attachment>,
120 pub banner: Option<Attachment>,
122
123 pub flags: Option<ServerFlags>,
125
126 #[serde(default)]
128 pub nsfw: bool,
129 #[serde(default)]
131 pub analytics: bool,
132 #[serde(default)]
134 pub discoverable: bool,
135}
136
137#[derive(Deserialize, Debug, Clone)]
139pub struct PartialServer {
140 pub owner: Option<String>,
142
143 pub name: Option<String>,
145 pub description: Option<String>,
147
148 pub channels: Option<Vec<String>>,
151 pub categories: Option<Vec<Category>>,
153 pub system_messages: Option<SystemMessageChannels>,
155
156 pub roles: Option<HashMap<String, Role>>,
158 pub default_permissions: Option<Permission>,
160
161 pub icon: Option<Attachment>,
163 pub banner: Option<Attachment>,
165
166 pub flags: Option<ServerFlags>,
168
169 pub nsfw: Option<bool>,
171 pub analytics: Option<bool>,
173 pub discoverable: Option<bool>,
175}
176
177#[derive(Deserialize, Debug, Clone)]
179pub struct ServerBan {
180 #[serde(rename = "_id")]
182 pub id: MemberCompositeKey,
183 pub reason: Option<String>,
185}
186
187#[derive(Deserialize, Debug, Clone)]
191pub struct BannedUser {
192 #[serde(rename = "_id")]
194 pub id: String,
195 pub username: String,
197 pub avatar: Option<Attachment>,
199}
200
201#[derive(Deserialize, Debug, Clone)]
203pub struct BanList {
204 pub users: Vec<BannedUser>,
206 pub bans: Vec<ServerBan>,
208}
209
210#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
212pub enum FieldsServer {
213 Description,
214 Categories,
215 SystemMessages,
216 Icon,
217 Banner,
218}
219
220#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
222pub enum FieldsRole {
223 Colour,
224}