1use std::fmt::{Display, Formatter};
2
3use serde::{Deserialize, Serialize};
4use serde_either::StringOrStruct;
5use time::OffsetDateTime;
6use url::Url;
7use uuid::Uuid;
8
9#[derive(Debug, Serialize, Deserialize, Clone)]
10pub struct PkId(pub String);
11
12impl Display for PkId {
13 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
14 f.write_str(self.0.as_str())
15 }
16}
17
18#[derive(Deserialize, Serialize, Debug)]
19pub struct System {
20 pub id: PkId,
21 pub uuid: Uuid,
22 pub name: Option<String>,
23 pub description: Option<String>,
24 pub color: Option<String>,
25 pub tag: Option<String>,
26 pub avatar_url: Option<Url>,
27 #[serde(with = "time::serde::rfc3339::option")]
28 pub created: Option<OffsetDateTime>,
29 pub privacy: Option<SystemPrivacy>,
30}
31
32#[derive(Deserialize, Serialize, Debug)]
33pub struct SystemPrivacy {
34 pub description_privacy: Privacy,
35 pub pronoun_privacy: Privacy,
36 pub member_list_privacy: Privacy,
37 pub group_list_privacy: Privacy,
38 pub front_privacy: Privacy,
39 pub front_history_privacy: Privacy,
40}
41
42#[derive(Deserialize, Serialize, Debug)]
43pub struct Member {
44 pub id: PkId,
45 pub uuid: Uuid,
46 pub name: String,
47 pub display_name: Option<String>,
48 pub color: Option<String>,
49 pub birthday: Option<String>,
50 pub pronouns: Option<String>,
51 pub avatar_url: Option<Url>,
52 pub webhook_avatar_url: Option<Url>,
53 pub banner: Option<Url>,
54 pub description: Option<String>,
55 #[serde(with = "time::serde::rfc3339::option")]
56 pub created: Option<OffsetDateTime>,
57 pub proxy_tags: Vec<ProxyTag>,
58 pub keep_proxy: bool,
59 pub autoproxy_enabled: Option<bool>,
60 pub message_count: Option<i32>,
61 #[serde(with = "time::serde::rfc3339::option")]
62 pub last_message_timestamp: Option<OffsetDateTime>,
63 pub privacy: Option<MemberPrivacy>,
64}
65
66#[derive(Deserialize, Serialize, Debug)]
67pub struct MemberPrivacy {
68 pub visibility: Privacy,
69 pub name_privacy: Privacy,
70 pub description_privacy: Privacy,
71 pub birthday_privacy: Privacy,
72 pub pronoun_privacy: Privacy,
73 pub avatar_privacy: Privacy,
74 pub metadata_privacy: Privacy,
75}
76
77#[derive(Deserialize, Serialize, Debug)]
78pub struct ProxyTag {
79 pub prefix: Option<String>,
80 pub suffix: Option<String>,
81}
82
83#[derive(Deserialize, Serialize, Debug)]
84pub struct Group {
85 pub id: PkId,
86 pub uuid: Uuid,
87 pub name: String,
88 pub display_name: Option<String>,
89 pub description: Option<String>,
90 pub icon: Option<Url>,
91 pub banner: Option<Url>,
92 pub color: Option<String>,
93 pub privacy: Option<GroupPrivacy>,
94}
95
96#[derive(Deserialize, Serialize, Debug)]
97pub struct GroupPrivacy {
98 pub name_privacy: Privacy,
99 pub description_privacy: Privacy,
100 pub icon_privacy: Privacy,
101 pub list_privacy: Privacy,
102 pub metadata_privacy: Privacy,
103 pub visibility: Privacy,
104}
105
106#[derive(Deserialize, Serialize, Debug)]
107pub struct Switch {
108 pub id: Uuid,
109 #[serde(with = "time::serde::rfc3339")]
110 pub timestamp: OffsetDateTime,
111 pub members: Vec<StringOrStruct<Member>>,
112}
113
114#[derive(Deserialize, Debug)]
115pub struct Message {
116 #[serde(with = "time::serde::rfc3339")]
117 pub timestamp: OffsetDateTime,
118 pub id: String,
119 pub original: String,
120 pub sender: String,
121 pub channel: String,
122 pub guild: String,
123 pub system: Option<System>,
124 pub member: Option<Member>,
125}
126
127#[derive(Deserialize, Serialize, Debug)]
128pub struct SystemSettings {
129 pub timezone: String,
130 pub pings_enabled: bool,
131 pub latch_timeout: Option<i32>,
132 pub member_default_private: bool,
133 pub group_default_private: bool,
134 pub show_private_info: bool,
135 pub member_limit: i32,
136 pub group_limit: i32,
137}
138
139#[derive(Deserialize, Serialize, Debug)]
140pub struct SystemGuildSettings {
141 pub guild_id: Option<String>,
142 pub proxying_enabled: bool,
143 pub tag: Option<String>,
144 pub tag_enabled: bool,
145}
146
147#[derive(Deserialize, Serialize, Debug)]
148pub struct AutoProxySettings {
149 pub autoproxy_mode: AutoProxyMode,
150 pub autoproxy_member: Option<String>,
151 #[serde(with = "time::serde::rfc3339::option")]
152 pub last_latch_timestamp: Option<OffsetDateTime>,
153}
154
155#[derive(Deserialize, Serialize, Debug, Clone)]
156#[serde(rename_all = "lowercase")]
157pub enum AutoProxyMode {
158 Off,
159 Front,
160 Latch,
161 Member,
162}
163
164#[derive(Deserialize, Serialize, Debug, Clone)]
165#[serde(rename_all = "lowercase")]
166pub enum Privacy {
167 Public,
168 Private,
169}
170
171#[derive(Deserialize, Serialize, Debug)]
172pub struct MemberGuildSettings {
173 pub guild_id: String,
174 pub display_name: Option<String>,
175 pub avatar_url: Option<Url>,
176}