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
#[derive(Serialize, Deserialize, Clone)]
pub struct BlockStyle {
    #[serde(rename = "backgroundColor", skip_serializing_if = "String::is_empty")]
    background_color: String,
    separator       : bool,
    #[serde(rename = "separatorColor", skip_serializing_if = "String::is_empty")]
    separator_color : String,
    #[serde(skip)]
    is_empty        : bool,
}

impl BlockStyle {
    pub fn new(background_color: &str, separator: bool, separator_color: &str) -> BlockStyle {
        BlockStyle {
            background_color: String::from(background_color),
            separator,
            separator_color : String::from(separator_color),
            is_empty        : false,
        }
    }

    pub fn create_empty() -> BlockStyle {
        BlockStyle {
            background_color: String::new(),
            separator       : false,
            separator_color : String::new(),
            is_empty        : true,
        }
    }

    pub fn is_empty(&self) -> bool { self.is_empty }
}

#[derive(Serialize, Deserialize, Clone)]
pub struct BubbleStyle {
    #[serde(skip_serializing_if = "BlockStyle::is_empty")]
    header  : BlockStyle,
    #[serde(skip_serializing_if = "BlockStyle::is_empty")]
    hero    : BlockStyle,
    #[serde(skip_serializing_if = "BlockStyle::is_empty")]
    body    : BlockStyle,
    #[serde(skip_serializing_if = "BlockStyle::is_empty")]
    footer  : BlockStyle,
    #[serde(skip)]
    is_empty: bool,
}

impl BubbleStyle {
    pub fn new(header: BlockStyle, hero: BlockStyle, body: BlockStyle, footer: BlockStyle) -> BubbleStyle {
        BubbleStyle { header, hero, body, footer , is_empty: false }
    }

    pub fn create_empty() -> BubbleStyle {
        BubbleStyle {
            header  : BlockStyle::create_empty(),
            hero    : BlockStyle::create_empty(),
            body    : BlockStyle::create_empty(),
            footer  : BlockStyle::create_empty(),
            is_empty: true,
        }
    }

    pub fn is_empty(&self) -> bool { self.is_empty }    
}

#[derive(Serialize, Deserialize, Clone)]
#[serde(untagged)]
pub enum Style {
    Bubble { styles: BubbleStyle },
    BlockStyle { styles: BlockStyle },
    Empty,
}

impl Style {
    pub fn is_empty(&self) -> bool {
        match self {
            Style::Empty => true,
            _            => false
        }
    }
}

// #[derive(Serialize, Deserialize, Clone)]
// #[serde(tag = "type", rename_all = "camelCase")]
// pub enum StyleType {
//     Block: BlockStyle,
//     Bubble: Bu
// }

// #[derive(Serialize, Deserialize, Clone)]
// pub struct Style {
//     kind: StyleType,
// }

// impl Style {
//     pub fn new(kind: StyleType) -> Style { Style { kind } }

//     pub fn create_empty() -> Style { Style { StyleType::Empty} }

//     pub fn create_bubble(header: StyleType, hero: StyleType, body: StyleType, footer: StyleType) -> Style {
//         Style { kind: StyleType::Bubble { header, hero, body, footer }}
//     }

//     pub fn create_block(background_color: &str, separator: &str, separator_color) -> Style {
//         Style {
//             background_color: String::from(background_color),
//             separator       : String::from(separator),
//             separator_color : String::from(separator_color),
//         }
//     }

//     pub fn is_empty(&self) -> bool {
//         match self.kind {
//             StyleType::Empty => true,
//             _                => false,
//         }
//     }
// }