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
pub use
crate::api::format::align::FormatAlign;
pub use crate::api::format::align::FormatAlignType;
pub use crate::api::format::border::{FormatBorder, FormatBorderElement, FormatBorderType};
pub use color::FormatColor;
pub use crate::api::format::fill::FormatFill;
pub use font::FormatFont;

mod align;
mod color;
mod fill;
mod font;
pub mod border;

#[derive(Default, Clone, Debug)]
pub struct Format {
    pub font: FormatFont,
    pub border: FormatBorder,
    pub fill: FormatFill,
    pub align: FormatAlign,
}

impl Format {
    pub fn is_bold(&self) -> bool {
        self.font.bold
    }

    pub fn is_italic(&self) -> bool {
        self.font.italic
    }

    pub fn is_underline(&self) -> bool {
        self.font.underline
    }

    pub fn get_size(&self) -> f64 {
        self.font.size
    }

    pub fn get_background(&self) -> &FormatFill {
        &self.fill
    }

    pub fn get_borders(&self) -> &FormatBorder {
        &self.border
    }
}

impl Format {
    pub fn set_bold(mut self) -> Self {
        self.font.bold = true;
        self
    }

    pub fn set_italic(mut self) -> Self {
        self.font.italic = true;
        self
    }

    pub fn set_underline(mut self) -> Self {
        self.font.underline = true;
        self
    }

    pub fn set_size(mut self, size: u8) -> Self {
        self.font.size = size as f64;
        self
    }

    pub fn set_size_f64(mut self, size: f64) -> Self {
        self.font.size = size;
        self
    }

    pub fn set_color(mut self, format_color: FormatColor) -> Self {
        self.font.color = format_color;
        self
    }

    pub fn set_font(mut self, font_name: &str) -> Self {
        self.font.name = font_name.to_string();
        self
    }

    pub fn set_border(mut self, format_border_type: FormatBorderType) -> Self {
        let mut format_border = FormatBorderElement::default();
        format_border.border_type = format_border_type;
        self.border.left = format_border.clone();
        self.border.right = format_border.clone();
        self.border.top = format_border.clone();
        self.border.bottom = format_border.clone();
        self.border.diagonal = format_border;
        self
    }

    pub fn set_border_left(mut self, format_border_type: FormatBorderType) -> Self {
        let mut format_border = FormatBorderElement::default();
        format_border.border_type = format_border_type;
        self.border.left = format_border;
        self
    }

    pub fn set_border_right(mut self, format_border_type: FormatBorderType) -> Self {
        let mut format_border = FormatBorderElement::default();
        format_border.border_type = format_border_type;
        self.border.right = format_border;
        self
    }

    pub fn set_border_top(mut self, format_border_type: FormatBorderType) -> Self {
        let mut format_border = FormatBorderElement::default();
        format_border.border_type = format_border_type;
        self.border.top = format_border;
        self
    }

    pub fn set_border_bottom(mut self, format_border_type: FormatBorderType) -> Self {
        let mut format_border = FormatBorderElement::default();
        format_border.border_type = format_border_type;
        self.border.bottom = format_border;
        self
    }

    pub fn set_background_color(mut self, format_color: FormatColor) -> Self {
        self.fill.pattern_type = "solid".to_string();
        self.fill.fg_color = format_color;
        self
    }

    pub fn set_align(mut self, format_align_type: FormatAlignType) -> Self {
        match format_align_type {
            FormatAlignType::Left | FormatAlignType::Center | FormatAlignType::Right =>
                self.align.horizontal = Some(format_align_type),
            FormatAlignType::Top | FormatAlignType::VerticalCenter | FormatAlignType::Bottom =>
                self.align.vertical = Some(format_align_type),
        }
        self
    }

    pub fn set_reading_order(mut self, reading_order: u8) -> Self {
        self.align.reading_order = Some(reading_order);
        self
    }

    pub fn set_indent(mut self, indent: u8) -> Self {
        self.align.indent = Some(indent);
        self
    }
}