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
use crate::responses::topics::Topics;
use chrono::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct Spaces {
    pub id: String,
    pub host_ids: Option<Vec<String>>,
    pub created_at: Option<DateTime<Utc>>,
    pub creator_id: Option<String>,
    pub ended_at: Option<DateTime<Utc>>,
    pub lang: Option<String>,
    pub is_ticketed: Option<bool>,
    pub invited_user_ids: Option<Vec<String>>,
    pub participant_count: Option<i64>,
    pub scheduled_start: Option<DateTime<Utc>>,
    pub speaker_ids: Option<Vec<String>>,
    pub started_at: Option<DateTime<Utc>>,
    pub state: State,
    pub subscriber_count: Option<i64>,
    pub topic_ids: Option<Vec<String>>,
    pub topics: Option<Vec<Topics>>,
    pub title: Option<String>,
    pub updated_at: Option<DateTime<Utc>>,
    #[serde(flatten)]
    pub extra: std::collections::HashMap<String, serde_json::Value>,
}

impl Spaces {
    pub fn is_empty_extra(&self) -> bool {
        let res = self.extra.is_empty()
            && self
                .topics
                .as_ref()
                .map(|it| it.iter().all(|item| item.is_empty_extra()))
                .unwrap_or(true);
        if !res {
            println!("Spaces {:?}", self.extra);
        }
        res
    }
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum State {
    #[serde(rename = "live")]
    Live,
    #[serde(rename = "scheduled")]
    Scheduled,
}

impl std::fmt::Display for State {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Self::Live => write!(f, "live"),
            Self::Scheduled => write!(f, "scheduled"),
        }
    }
}

impl Default for State {
    fn default() -> Self {
        Self::Live
    }
}