1#![allow(unused_imports, clippy::doc_markdown, clippy::struct_excessive_bools)]
7#![allow(
8 clippy::too_many_lines,
9 clippy::too_many_arguments,
10 clippy::wildcard_imports
11)]
12#![allow(clippy::match_same_arms, clippy::fn_params_excessive_bools)]
13
14use alloc::string::String;
15use alloc::vec::Vec;
16
17use serde::{Deserialize, Serialize};
18
19use super::enums::*;
20use crate::validate::{self, Validate, ValidationPath, Violations};
21
22#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
24pub struct AuthorizationData {
25 #[serde(rename = "idTag")]
27 pub id_tag: String,
28 #[serde(rename = "idTagInfo")]
30 #[serde(default, skip_serializing_if = "Option::is_none")]
31 pub id_tag_info: Option<IdTagInfo>,
32}
33
34impl AuthorizationData {
35 #[must_use]
37 pub fn new(id_tag: impl Into<String>) -> Self {
38 Self {
39 id_tag: id_tag.into(),
40 id_tag_info: None,
41 }
42 }
43
44 #[must_use]
46 pub fn with_id_tag_info(mut self, value: IdTagInfo) -> Self {
47 self.id_tag_info = Some(value);
48 self
49 }
50}
51
52impl Validate for AuthorizationData {
53 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
54 path.push_key("idTag");
55 validate::string(self.id_tag.as_str(), None, Some(20), path, out);
56 path.pop();
57 path.push_key("idTagInfo");
58 if let Some(value) = &self.id_tag_info {
59 Validate::validate_at(value, path, out);
60 }
61 path.pop();
62 }
63}
64
65#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
67pub struct CertificateHashData {
68 #[serde(rename = "hashAlgorithm")]
70 pub hash_algorithm: HashAlgorithm,
71 #[serde(rename = "issuerNameHash")]
73 pub issuer_name_hash: String,
74 #[serde(rename = "issuerKeyHash")]
76 pub issuer_key_hash: String,
77 #[serde(rename = "serialNumber")]
79 pub serial_number: String,
80}
81
82impl CertificateHashData {
83 #[must_use]
85 pub fn new(
86 hash_algorithm: HashAlgorithm,
87 issuer_name_hash: impl Into<String>,
88 issuer_key_hash: impl Into<String>,
89 serial_number: impl Into<String>,
90 ) -> Self {
91 Self {
92 hash_algorithm,
93 issuer_name_hash: issuer_name_hash.into(),
94 issuer_key_hash: issuer_key_hash.into(),
95 serial_number: serial_number.into(),
96 }
97 }
98}
99
100impl Validate for CertificateHashData {
101 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
102 path.push_key("hashAlgorithm");
103 Validate::validate_at(&self.hash_algorithm, path, out);
104 path.pop();
105 path.push_key("issuerNameHash");
106 validate::string(self.issuer_name_hash.as_str(), None, Some(128), path, out);
107 path.pop();
108 path.push_key("issuerKeyHash");
109 validate::string(self.issuer_key_hash.as_str(), None, Some(128), path, out);
110 path.pop();
111 path.push_key("serialNumber");
112 validate::string(self.serial_number.as_str(), None, Some(40), path, out);
113 path.pop();
114 }
115}
116
117#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
119pub struct ChargingProfile {
120 #[serde(rename = "chargingProfileId")]
122 pub charging_profile_id: i32,
123 #[serde(rename = "stackLevel")]
125 pub stack_level: i32,
126 #[serde(rename = "chargingProfilePurpose")]
128 pub charging_profile_purpose: ChargingProfilePurpose,
129 #[serde(rename = "chargingProfileKind")]
131 pub charging_profile_kind: ChargingProfileKind,
132 #[serde(rename = "chargingSchedule")]
134 pub charging_schedule: ChargingSchedule,
135 #[serde(rename = "transactionId")]
137 #[serde(default, skip_serializing_if = "Option::is_none")]
138 pub transaction_id: Option<i32>,
139 #[serde(rename = "recurrencyKind")]
141 #[serde(default, skip_serializing_if = "Option::is_none")]
142 pub recurrency_kind: Option<RecurrencyKind>,
143 #[serde(rename = "validFrom")]
145 #[serde(default, skip_serializing_if = "Option::is_none")]
146 pub valid_from: Option<crate::types::DateTime>,
147 #[serde(rename = "validTo")]
149 #[serde(default, skip_serializing_if = "Option::is_none")]
150 pub valid_to: Option<crate::types::DateTime>,
151}
152
153impl ChargingProfile {
154 #[must_use]
156 pub fn new(
157 charging_profile_id: i32,
158 stack_level: i32,
159 charging_profile_purpose: ChargingProfilePurpose,
160 charging_profile_kind: ChargingProfileKind,
161 charging_schedule: ChargingSchedule,
162 ) -> Self {
163 Self {
164 charging_profile_id,
165 stack_level,
166 charging_profile_purpose,
167 charging_profile_kind,
168 charging_schedule,
169 transaction_id: None,
170 recurrency_kind: None,
171 valid_from: None,
172 valid_to: None,
173 }
174 }
175
176 #[must_use]
178 pub fn with_transaction_id(mut self, value: i32) -> Self {
179 self.transaction_id = Some(value);
180 self
181 }
182
183 #[must_use]
185 pub fn with_recurrency_kind(mut self, value: RecurrencyKind) -> Self {
186 self.recurrency_kind = Some(value);
187 self
188 }
189
190 #[must_use]
192 pub fn with_valid_from(mut self, value: impl Into<crate::types::DateTime>) -> Self {
193 self.valid_from = Some(value.into());
194 self
195 }
196
197 #[must_use]
199 pub fn with_valid_to(mut self, value: impl Into<crate::types::DateTime>) -> Self {
200 self.valid_to = Some(value.into());
201 self
202 }
203}
204
205impl Validate for ChargingProfile {
206 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
207 path.push_key("chargingProfilePurpose");
208 Validate::validate_at(&self.charging_profile_purpose, path, out);
209 path.pop();
210 path.push_key("chargingProfileKind");
211 Validate::validate_at(&self.charging_profile_kind, path, out);
212 path.pop();
213 path.push_key("chargingSchedule");
214 Validate::validate_at(&self.charging_schedule, path, out);
215 path.pop();
216 path.push_key("recurrencyKind");
217 if let Some(value) = &self.recurrency_kind {
218 Validate::validate_at(value, path, out);
219 }
220 path.pop();
221 }
222}
223
224#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
226pub struct ChargingSchedule {
227 #[serde(rename = "chargingRateUnit")]
229 pub charging_rate_unit: ChargingRateUnit,
230 #[serde(rename = "chargingSchedulePeriod")]
232 pub charging_schedule_period: Vec<ChargingSchedulePeriod>,
233 #[serde(default, skip_serializing_if = "Option::is_none")]
235 pub duration: Option<i32>,
236 #[serde(rename = "startSchedule")]
238 #[serde(default, skip_serializing_if = "Option::is_none")]
239 pub start_schedule: Option<crate::types::DateTime>,
240 #[serde(rename = "minChargingRate")]
242 #[serde(default, skip_serializing_if = "Option::is_none")]
243 pub min_charging_rate: Option<crate::types::Decimal>,
244}
245
246impl ChargingSchedule {
247 #[must_use]
249 pub fn new(
250 charging_rate_unit: ChargingRateUnit,
251 charging_schedule_period: Vec<ChargingSchedulePeriod>,
252 ) -> Self {
253 Self {
254 charging_rate_unit,
255 charging_schedule_period,
256 duration: None,
257 start_schedule: None,
258 min_charging_rate: None,
259 }
260 }
261
262 #[must_use]
264 pub fn with_duration(mut self, value: i32) -> Self {
265 self.duration = Some(value);
266 self
267 }
268
269 #[must_use]
271 pub fn with_start_schedule(mut self, value: impl Into<crate::types::DateTime>) -> Self {
272 self.start_schedule = Some(value.into());
273 self
274 }
275
276 #[must_use]
278 pub fn with_min_charging_rate(mut self, value: impl Into<crate::types::Decimal>) -> Self {
279 self.min_charging_rate = Some(value.into());
280 self
281 }
282}
283
284impl Validate for ChargingSchedule {
285 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
286 path.push_key("chargingRateUnit");
287 Validate::validate_at(&self.charging_rate_unit, path, out);
288 path.pop();
289 path.push_key("chargingSchedulePeriod");
290 for (index, item) in self.charging_schedule_period.iter().enumerate() {
291 path.push_index(index);
292 Validate::validate_at(item, path, out);
293 path.pop();
294 }
295 path.pop();
296 }
297}
298
299#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
301pub struct ChargingSchedulePeriod {
302 #[serde(rename = "startPeriod")]
304 pub start_period: i32,
305 pub limit: crate::types::Decimal,
307 #[serde(rename = "numberPhases")]
309 #[serde(default, skip_serializing_if = "Option::is_none")]
310 pub number_phases: Option<i32>,
311}
312
313impl ChargingSchedulePeriod {
314 #[must_use]
316 pub fn new(start_period: i32, limit: impl Into<crate::types::Decimal>) -> Self {
317 Self {
318 start_period,
319 limit: limit.into(),
320 number_phases: None,
321 }
322 }
323
324 #[must_use]
326 pub fn with_number_phases(mut self, value: i32) -> Self {
327 self.number_phases = Some(value);
328 self
329 }
330}
331
332impl Validate for ChargingSchedulePeriod {
333 fn validate_at(&self, _path: &mut ValidationPath, _out: &mut Violations) {}
334}
335
336#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
338pub struct Firmware {
339 pub location: String,
341 #[serde(rename = "retrieveDateTime")]
343 pub retrieve_date_time: crate::types::DateTime,
344 #[serde(rename = "signingCertificate")]
346 pub signing_certificate: String,
347 pub signature: String,
349 #[serde(rename = "installDateTime")]
351 #[serde(default, skip_serializing_if = "Option::is_none")]
352 pub install_date_time: Option<crate::types::DateTime>,
353}
354
355impl Firmware {
356 #[must_use]
358 pub fn new(
359 location: impl Into<String>,
360 retrieve_date_time: impl Into<crate::types::DateTime>,
361 signing_certificate: impl Into<String>,
362 signature: impl Into<String>,
363 ) -> Self {
364 Self {
365 location: location.into(),
366 retrieve_date_time: retrieve_date_time.into(),
367 signing_certificate: signing_certificate.into(),
368 signature: signature.into(),
369 install_date_time: None,
370 }
371 }
372
373 #[must_use]
375 pub fn with_install_date_time(mut self, value: impl Into<crate::types::DateTime>) -> Self {
376 self.install_date_time = Some(value.into());
377 self
378 }
379}
380
381impl Validate for Firmware {
382 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
383 path.push_key("location");
384 validate::string(self.location.as_str(), None, Some(512), path, out);
385 path.pop();
386 path.push_key("signingCertificate");
387 validate::string(
388 self.signing_certificate.as_str(),
389 None,
390 Some(5500),
391 path,
392 out,
393 );
394 path.pop();
395 path.push_key("signature");
396 validate::string(self.signature.as_str(), None, Some(800), path, out);
397 path.pop();
398 }
399}
400
401#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
403pub struct IdTagInfo {
404 pub status: AuthorizationStatus,
406 #[serde(rename = "expiryDate")]
408 #[serde(default, skip_serializing_if = "Option::is_none")]
409 pub expiry_date: Option<crate::types::DateTime>,
410 #[serde(rename = "parentIdTag")]
412 #[serde(default, skip_serializing_if = "Option::is_none")]
413 pub parent_id_tag: Option<String>,
414}
415
416impl IdTagInfo {
417 #[must_use]
419 pub fn new(status: AuthorizationStatus) -> Self {
420 Self {
421 status,
422 expiry_date: None,
423 parent_id_tag: None,
424 }
425 }
426
427 #[must_use]
429 pub fn with_expiry_date(mut self, value: impl Into<crate::types::DateTime>) -> Self {
430 self.expiry_date = Some(value.into());
431 self
432 }
433
434 #[must_use]
436 pub fn with_parent_id_tag(mut self, value: impl Into<String>) -> Self {
437 self.parent_id_tag = Some(value.into());
438 self
439 }
440}
441
442impl Validate for IdTagInfo {
443 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
444 path.push_key("status");
445 Validate::validate_at(&self.status, path, out);
446 path.pop();
447 path.push_key("parentIdTag");
448 if let Some(value) = &self.parent_id_tag {
449 validate::string(value.as_str(), None, Some(20), path, out);
450 }
451 path.pop();
452 }
453}
454
455#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
457pub struct KeyValue {
458 pub key: String,
460 pub readonly: bool,
462 #[serde(default, skip_serializing_if = "Option::is_none")]
464 pub value: Option<String>,
465}
466
467impl KeyValue {
468 #[must_use]
470 pub fn new(key: impl Into<String>, readonly: bool) -> Self {
471 Self {
472 key: key.into(),
473 readonly,
474 value: None,
475 }
476 }
477
478 #[must_use]
480 pub fn with_value(mut self, value: impl Into<String>) -> Self {
481 self.value = Some(value.into());
482 self
483 }
484}
485
486impl Validate for KeyValue {
487 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
488 path.push_key("key");
489 validate::string(self.key.as_str(), None, Some(50), path, out);
490 path.pop();
491 path.push_key("value");
492 if let Some(value) = &self.value {
493 validate::string(value.as_str(), None, Some(500), path, out);
494 }
495 path.pop();
496 }
497}
498
499#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
501pub struct LogParameters {
502 #[serde(rename = "remoteLocation")]
504 pub remote_location: String,
505 #[serde(rename = "oldestTimestamp")]
507 #[serde(default, skip_serializing_if = "Option::is_none")]
508 pub oldest_timestamp: Option<crate::types::DateTime>,
509 #[serde(rename = "latestTimestamp")]
511 #[serde(default, skip_serializing_if = "Option::is_none")]
512 pub latest_timestamp: Option<crate::types::DateTime>,
513}
514
515impl LogParameters {
516 #[must_use]
518 pub fn new(remote_location: impl Into<String>) -> Self {
519 Self {
520 remote_location: remote_location.into(),
521 oldest_timestamp: None,
522 latest_timestamp: None,
523 }
524 }
525
526 #[must_use]
528 pub fn with_oldest_timestamp(mut self, value: impl Into<crate::types::DateTime>) -> Self {
529 self.oldest_timestamp = Some(value.into());
530 self
531 }
532
533 #[must_use]
535 pub fn with_latest_timestamp(mut self, value: impl Into<crate::types::DateTime>) -> Self {
536 self.latest_timestamp = Some(value.into());
537 self
538 }
539}
540
541impl Validate for LogParameters {
542 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
543 path.push_key("remoteLocation");
544 validate::string(self.remote_location.as_str(), None, Some(512), path, out);
545 path.pop();
546 }
547}
548
549#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
551pub struct MeterValue {
552 pub timestamp: crate::types::DateTime,
554 #[serde(rename = "sampledValue")]
556 pub sampled_value: Vec<SampledValue>,
557}
558
559impl MeterValue {
560 #[must_use]
562 pub fn new(
563 timestamp: impl Into<crate::types::DateTime>,
564 sampled_value: Vec<SampledValue>,
565 ) -> Self {
566 Self {
567 timestamp: timestamp.into(),
568 sampled_value,
569 }
570 }
571}
572
573impl Validate for MeterValue {
574 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
575 path.push_key("sampledValue");
576 validate::list_len(self.sampled_value.len(), Some(1), None, path, out);
577 for (index, item) in self.sampled_value.iter().enumerate() {
578 path.push_index(index);
579 Validate::validate_at(item, path, out);
580 path.pop();
581 }
582 path.pop();
583 }
584}
585
586#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
588pub struct SampledValue {
589 pub value: String,
591 #[serde(default, skip_serializing_if = "Option::is_none")]
593 pub context: Option<ReadingContext>,
594 #[serde(default, skip_serializing_if = "Option::is_none")]
596 pub format: Option<ValueFormat>,
597 #[serde(default, skip_serializing_if = "Option::is_none")]
599 pub measurand: Option<Measurand>,
600 #[serde(default, skip_serializing_if = "Option::is_none")]
602 pub phase: Option<Phase>,
603 #[serde(default, skip_serializing_if = "Option::is_none")]
605 pub location: Option<Location>,
606 #[serde(default, skip_serializing_if = "Option::is_none")]
608 pub unit: Option<UnitOfMeasure>,
609}
610
611impl SampledValue {
612 #[must_use]
614 pub fn new(value: impl Into<String>) -> Self {
615 Self {
616 value: value.into(),
617 context: None,
618 format: None,
619 measurand: None,
620 phase: None,
621 location: None,
622 unit: None,
623 }
624 }
625
626 #[must_use]
628 pub fn with_context(mut self, value: ReadingContext) -> Self {
629 self.context = Some(value);
630 self
631 }
632
633 #[must_use]
635 pub fn with_format(mut self, value: ValueFormat) -> Self {
636 self.format = Some(value);
637 self
638 }
639
640 #[must_use]
642 pub fn with_measurand(mut self, value: Measurand) -> Self {
643 self.measurand = Some(value);
644 self
645 }
646
647 #[must_use]
649 pub fn with_phase(mut self, value: Phase) -> Self {
650 self.phase = Some(value);
651 self
652 }
653
654 #[must_use]
656 pub fn with_location(mut self, value: Location) -> Self {
657 self.location = Some(value);
658 self
659 }
660
661 #[must_use]
663 pub fn with_unit(mut self, value: UnitOfMeasure) -> Self {
664 self.unit = Some(value);
665 self
666 }
667}
668
669impl Validate for SampledValue {
670 fn validate_at(&self, path: &mut ValidationPath, out: &mut Violations) {
671 path.push_key("context");
672 if let Some(value) = &self.context {
673 Validate::validate_at(value, path, out);
674 }
675 path.pop();
676 path.push_key("format");
677 if let Some(value) = &self.format {
678 Validate::validate_at(value, path, out);
679 }
680 path.pop();
681 path.push_key("measurand");
682 if let Some(value) = &self.measurand {
683 Validate::validate_at(value, path, out);
684 }
685 path.pop();
686 path.push_key("phase");
687 if let Some(value) = &self.phase {
688 Validate::validate_at(value, path, out);
689 }
690 path.pop();
691 path.push_key("location");
692 if let Some(value) = &self.location {
693 Validate::validate_at(value, path, out);
694 }
695 path.pop();
696 path.push_key("unit");
697 if let Some(value) = &self.unit {
698 Validate::validate_at(value, path, out);
699 }
700 path.pop();
701 }
702}