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
use std::fmt::Display;

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct User {
    pub id: String,
    pub username: String,
    pub discriminator: String,
    #[serde(default)]
    pub avatar: Option<String>,
    #[serde(default)]
    pub public_flags: u64,
    #[serde(default)]
    pub flags: u64,
    #[serde(default)]
    pub premium_type: u8,
    #[serde(default)]
    pub global_name: Option<String>,
    #[serde(default)]
    pub bot: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Application {
    pub id: String,
    pub name: String,
    pub description: String,
    #[serde(default)]
    pub icon: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Channel {}

#[derive(Serialize, Deserialize, Debug)]
pub struct Activity {}

#[derive(Serialize, Deserialize, Debug)]
pub struct SdkConfiguration {
    #[serde(rename = "disableConsoleLogOverride")]
    pub disable_console_log_override: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct AuthorizeArgs {
    pub client_id: String,
    pub response_type: String,
    pub state: String,
    pub prompt: String,
    pub scope: Vec<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct AuthorizeRes {
    pub code: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct AuthenticateArgs {
    pub access_token: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct AuthenticateRes {
    pub access_token: String,
    pub scopes: Vec<String>,
    pub expires: String,
    pub user: User,
    pub application: Application,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct CaputeLogArgs {
    pub level: String,
    pub message: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetChannelArgs {
    pub channel_id: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetChannelRes {
    #[serde(flatten)]
    pub channel: Channel,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetChannelPermissionsRes {
    // TODO: Implement this struct
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetInstanceConnectedParticipantsRes {
    pub participants: Vec<User>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetPlatformBehaviorsRes {
    // TODO: Implement this struct
}

#[derive(Serialize, Deserialize, Debug)]
pub struct InitiateImageUploadRes {
    // TODO: Implement this struct
}

#[derive(Serialize, Deserialize, Debug)]
pub struct OpenExternalLinkArgs {
    pub url: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct OpenShareMomentDialogArgs {
    #[serde(rename = "mediaUrl")]
    pub media_url: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SetActivityArgs {
    pub activity: Activity,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SetConfigArgs {
    pub user_interactive_pip: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SetOrientationLockStateArgs {
    pub lock_state: String,
    pub picture_in_picture_lock_state: String,
    pub grid_lock_state: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct UserSettingsGetLocaleRes {
    // TODO: Implement this struct
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReadyEvent {
    pub v: u8,
    pub config: ReadyEventConfig,
}

impl EventPayload for ReadyEvent {
    fn event_type() -> EventType {
        EventType::Ready
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ReadyEventConfig {
    cdn_host: String,
    api_endpoint: String,
    environment: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ErrorEvent {
    pub code: u64,
    pub message: String,
}

impl EventPayload for ErrorEvent {
    fn event_type() -> EventType {
        EventType::Error
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct VoiceStateUpdateEvent {
    pub voice_state: VoiceState,
    pub user: User,
    #[serde(default)]
    pub nick: Option<String>,
    pub volume: u32,
    pub mute: bool,
    #[serde(default)]
    pub pan: Option<VoiceStateUpdatePan>,
}

impl EventPayload for VoiceStateUpdateEvent {
    fn event_type() -> EventType {
        EventType::VoiceStateUpdate
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct VoiceState {
    pub mute: bool,
    pub deaf: bool,
    pub self_mute: bool,
    pub self_deaf: bool,
    pub suppress: bool,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct VoiceStateUpdatePan {
    pub left: f32,
    pub right: f32,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SpeakingStartEvent {
    pub channel_id: String,
    pub user_id: String,
}

impl EventPayload for SpeakingStartEvent {
    fn event_type() -> EventType {
        EventType::SpeakingStart
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SpeakingStopEvent {
    pub channel_id: String,
    pub user_id: String,
}

impl EventPayload for SpeakingStopEvent {
    fn event_type() -> EventType {
        EventType::SpeakingStop
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ActivityLayoutModeUpdateEvent {
    pub layout_mode: u8,
}

impl EventPayload for ActivityLayoutModeUpdateEvent {
    fn event_type() -> EventType {
        EventType::ActivityLayoutModeUpdate
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct OrientationUpdateEvent {
    pub screen_orientation: u8,
}

impl EventPayload for OrientationUpdateEvent {
    fn event_type() -> EventType {
        EventType::OrientationUpdate
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct CurrentUserUpdateEvent {
    #[serde(flatten)]
    pub user: User,
}

impl EventPayload for CurrentUserUpdateEvent {
    fn event_type() -> EventType {
        EventType::CurrentUserUpdate
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ThermalStateUpdateEvent {
    pub thermal_state: u8,
}

impl EventPayload for ThermalStateUpdateEvent {
    fn event_type() -> EventType {
        EventType::ThermalStateUpdate
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ActivityInstanceParticipantsUpdateEvent {
    pub participants: Vec<User>,
}

impl EventPayload for ActivityInstanceParticipantsUpdateEvent {
    fn event_type() -> EventType {
        EventType::ActivityInstanceParticipantsUpdate
    }
}

pub enum EventType {
    Ready,
    Error,
    VoiceStateUpdate,
    SpeakingStart,
    SpeakingStop,
    ActivityLayoutModeUpdate,
    OrientationUpdate,
    CurrentUserUpdate,
    ThermalStateUpdate,
    ActivityInstanceParticipantsUpdate,
}

impl EventType {
    pub fn as_str(&self) -> &str {
        match self {
            EventType::Ready => "READY",
            EventType::Error => "ERROR",
            EventType::VoiceStateUpdate => "VOICE_STATE_UPDATE",
            EventType::SpeakingStart => "SPEAKING_START",
            EventType::SpeakingStop => "SPEAKING_STOP",
            EventType::ActivityLayoutModeUpdate => "ACTIVITY_LAYOUT_MODE_UPDATE",
            EventType::OrientationUpdate => "ORIENTATION_UPDATE",
            EventType::CurrentUserUpdate => "CURRENT_USER_UPDATE",
            EventType::ThermalStateUpdate => "THERMAL_STATE_UPDATE",
            EventType::ActivityInstanceParticipantsUpdate => {
                "ACTIVITY_INSTANCE_PARTICIPANTS_UPDATE"
            }
        }
    }
}

impl Display for EventType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

pub trait EventPayload {
    fn event_type() -> EventType;
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SubscribeArgs {
    pub channel_id: String,
}

impl SubscribeArgs {
    pub fn channel_id<T>(channel_id: T) -> Self
    where
        T: Into<String>,
    {
        Self {
            channel_id: channel_id.into(),
        }
    }
}