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
use crate::configs::{parsing::generating::nodes as gen, SimpleId};
use serde::Deserialize;
pub mod metrics;

#[derive(Clone, Debug)]
pub struct Config {
    pub categories: Vec<Category>,
}

impl From<ProtoConfig> for Config {
    fn from(proto_cfg: ProtoConfig) -> Config {
        let mut categories: Vec<Category> = Vec::new();

        for category in proto_cfg.0.into_iter() {
            categories.push(category.into());
        }

        Config { categories }
    }
}

#[derive(Clone, Debug)]
pub enum Category {
    Meta {
        info: MetaInfo,
        id: SimpleId,
    },
    Metric {
        unit: metrics::UnitInfo,
        id: SimpleId,
    },
    Ignored,
}

impl From<ProtoCategory> for Category {
    fn from(proto_category: ProtoCategory) -> Category {
        match proto_category {
            ProtoCategory::Meta { info, id } => Category::Meta {
                info: MetaInfo::from(info),
                id,
            },
            ProtoCategory::Metric { unit, id } => Category::Metric {
                unit: metrics::UnitInfo::from(unit),
                id,
            },
            ProtoCategory::Ignored => Category::Ignored,
        }
    }
}

impl From<gen::Category> for Category {
    fn from(gen_category: gen::Category) -> Category {
        match gen_category {
            gen::Category::Meta { info, id } => Category::Meta {
                info: MetaInfo::from(info),
                id,
            },
        }
    }
}

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum MetaInfo {
    NodeId,
    NodeIdx,
    CHLevel,
}

impl From<ProtoMetaInfo> for MetaInfo {
    fn from(proto_info: ProtoMetaInfo) -> MetaInfo {
        match proto_info {
            ProtoMetaInfo::NodeId => MetaInfo::NodeId,
            ProtoMetaInfo::CHLevel => MetaInfo::CHLevel,
        }
    }
}

impl From<gen::MetaInfo> for MetaInfo {
    fn from(gen_info: gen::MetaInfo) -> MetaInfo {
        match gen_info {
            gen::MetaInfo::NodeId => MetaInfo::NodeId,
            gen::MetaInfo::NodeIdx => MetaInfo::NodeIdx,
            gen::MetaInfo::CHLevel => MetaInfo::CHLevel,
        }
    }
}

#[derive(Clone, Debug)]
pub struct ProtoConfig(pub Vec<ProtoCategory>);

impl From<RawConfig> for ProtoConfig {
    fn from(raw_cfg: RawConfig) -> ProtoConfig {
        ProtoConfig(raw_cfg.0.into_iter().map(ProtoCategory::from).collect())
    }
}

#[derive(Clone, Debug)]
pub enum ProtoCategory {
    Meta {
        info: ProtoMetaInfo,
        id: SimpleId,
    },
    Metric {
        unit: metrics::ProtoUnitInfo,
        id: SimpleId,
    },
    Ignored,
}

impl From<RawCategory> for ProtoCategory {
    fn from(raw_category: RawCategory) -> ProtoCategory {
        match raw_category {
            RawCategory::Meta { info, id } => ProtoCategory::Meta {
                info: ProtoMetaInfo::from(info),
                id,
            },
            RawCategory::Metric { unit, id } => ProtoCategory::Metric {
                unit: metrics::ProtoUnitInfo::from(unit),
                id,
            },
            RawCategory::Ignored => ProtoCategory::Ignored,
        }
    }
}

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ProtoMetaInfo {
    NodeId,
    CHLevel,
}

impl From<RawMetaInfo> for ProtoMetaInfo {
    fn from(raw_info: RawMetaInfo) -> ProtoMetaInfo {
        match raw_info {
            RawMetaInfo::NodeId => ProtoMetaInfo::NodeId,
            RawMetaInfo::CHLevel => ProtoMetaInfo::CHLevel,
        }
    }
}

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RawConfig(pub Vec<RawCategory>);

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum RawCategory {
    Meta {
        info: RawMetaInfo,
        id: SimpleId,
    },
    Metric {
        unit: metrics::RawUnitInfo,
        id: SimpleId,
    },
    Ignored,
}

#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq)]
pub enum RawMetaInfo {
    NodeId,
    CHLevel,
}