-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.rs
204 lines (190 loc) · 5.28 KB
/
mod.rs
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
#[cfg(feature = "proto")]
use proto_mapper::{derive::ProtoMap, ProtoMap, ProtoMapScalar, ProtoScalar};
use serde::{Deserialize, Serialize};
// Re export proto models on feature "proto"
// Re export proto_convert ProtoConvert on feature "proto"
#[cfg(feature = "proto")]
pub mod proto {
pub use claims_schema::proto::*;
pub use proto_mapper::ProtoMap;
}
// <editor-fold desc="Claim models">
#[derive(
Clone, Copy, Debug, Default, Serialize, Deserialize, strum::Display, strum::EnumString,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[cfg_attr(
feature = "sqlx",
sqlx(type_name = "VARCHAR", rename_all = "SCREAMING_SNAKE_CASE")
)]
#[cfg_attr(feature = "proto", derive(ProtoMap))]
#[cfg_attr(
feature = "proto",
proto_map(
source = "proto::claim::ClaimStatus",
enumeration,
rename_variants = "STREAMING_SNAKE_CASE"
)
)]
pub enum ClaimStatus {
#[default]
Open,
Closed,
Cancelled,
UnderRevision,
}
#[derive(
Clone, Copy, Debug, Default, Serialize, Deserialize, strum::Display, strum::EnumString,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[cfg_attr(
feature = "sqlx",
sqlx(type_name = "VARCHAR", rename_all = "SCREAMING_SNAKE_CASE")
)]
#[cfg_attr(feature = "proto", derive(ProtoMap))]
#[cfg_attr(
feature = "proto",
proto_map(
source = "proto::claim::IncidentType",
enumeration,
rename_variants = "STREAMING_SNAKE_CASE"
)
)]
pub enum IncidentType {
#[default]
OtherDamage,
Collision,
RoadAssistance,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "proto", derive(ProtoMap))]
#[cfg_attr(feature = "proto", proto_map(source = "proto::claim::Claim"))]
pub struct Claim {
pub id: i32,
pub claim_no: String,
pub status: ClaimStatus,
pub incident_type: IncidentType,
}
// </editor-fold>
// <editor-fold desc="Party models">
#[derive(
Clone, Copy, Debug, Default, Serialize, Deserialize, strum::Display, strum::EnumString,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[cfg_attr(
feature = "sqlx",
sqlx(type_name = "VARCHAR", rename_all = "SCREAMING_SNAKE_CASE")
)]
#[cfg_attr(feature = "proto", derive(ProtoMap))]
#[cfg_attr(
feature = "proto",
proto_map(
source = "proto::party::PartyType",
enumeration,
rename_variants = "STREAMING_SNAKE_CASE"
)
)]
pub enum PartyType {
#[default]
Person,
Vehicle,
}
#[derive(
Clone, Copy, Debug, Default, Serialize, Deserialize, strum::Display, strum::EnumString,
)]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
#[cfg_attr(
feature = "sqlx",
sqlx(type_name = "VARCHAR", rename_all = "SCREAMING_SNAKE_CASE")
)]
#[cfg_attr(feature = "proto", derive(ProtoMap))]
#[cfg_attr(
feature = "proto",
proto_map(
source = "proto::party::PartySubtype",
enumeration,
rename_variants = "STREAMING_SNAKE_CASE"
)
)]
pub enum PartySubtype {
Car,
Motorbike,
Owner,
Beneficiary,
Driver,
Passenger,
#[default]
Other,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "proto", derive(ProtoMap))]
#[cfg_attr(feature = "proto", proto_map(source = "proto::party::Party"))]
pub struct Party {
pub id: i32,
pub claim_id: i32,
#[cfg_attr(feature = "proto", proto_map(rename = "type_"))]
pub r#type: PartyType,
pub subtype: PartySubtype,
pub data: PartyData,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "type")]
#[cfg_attr(feature = "proto", derive(ProtoMap))]
#[cfg_attr(
feature = "proto",
proto_map(
source = "proto::party::PartyData",
one_of(field = "data"),
rename_variants = "snake_case"
)
)]
pub enum PartyData {
#[serde(rename = "PERSON")]
Person(Person),
#[serde(rename = "VEHICLE")]
Vehicle(Vehicle),
}
impl PartyData {
pub fn r#type(&self) -> PartyType {
match self {
PartyData::Vehicle(_) => PartyType::Vehicle,
PartyData::Person(_) => PartyType::Person,
}
}
pub fn subtype(&self) -> PartySubtype {
match self {
PartyData::Vehicle(v) => v.subtype,
PartyData::Person(v) => v.subtype,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "proto", derive(ProtoMap))]
#[cfg_attr(feature = "proto", proto_map(source = "proto::party::Person"))]
pub struct Person {
pub subtype: PartySubtype,
pub name: String,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "proto", derive(ProtoMap))]
#[cfg_attr(feature = "proto", proto_map(source = "proto::party::Vehicle"))]
pub struct Vehicle {
pub subtype: PartySubtype,
pub reg_no: String,
pub make: Option<String>,
pub model: Option<String>,
}
// </editor-fold>