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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
use crate::traits::{
    SEBillingMeterReadingBase, SEIdentifiedObject, SEList, SEMeterReadingBase, SEReadingBase,
    SEReadingSetBase, SEResource, SESubscribableList, SESubscribableResource, Validate,
};
use sep2_common_derive::{
    SEBillingMeterReadingBase, SEIdentifiedObject, SEList, SEMeterReadingBase, SEReadingBase,
    SEReadingSetBase, SEResource, SESubscribableList, SESubscribableResource,
};

use super::{
    links::{
        ActiveBillingPeriodListLink, ActiveProjectionReadingListLink, ActiveTargetReadingListLink,
        BillingPeriodListLink, BillingReadingListLink, BillingReadingSetListLink,
        CustomerAgreementListLink, HistoricalReadingListLink, PrepaymentLink,
        ProjectionReadingListLink, ReadingTypeLink, ServiceSupplierLink, TargetReadingListLink,
        TariffProfileLink, UsagePointLink,
    },
    primitives::{Int32, Int48, String20, String32, String42, Uint16, Uint32},
    types::{
        ConsumptionBlockType, DateTimeInterval, MRIDType, PowerOfTenMultiplierType, QualityFlags,
        SubscribableType, TOUType, TimeType, VersionType,
    },
};
use yaserde::{YaDeserialize, YaSerialize};

#[derive(Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize, SEResource)]
#[yaserde(rename = "BillingPeriod")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct BillingPeriod {
    /// The amount of the bill for the previous billing period.
    #[yaserde(rename = "billLastPeriod")]
    pub bill_last_period: Option<Int48>,

    /// The bill amount related to the billing period as of the statusTimeStamp.
    #[yaserde(rename = "billToDate")]
    pub bill_to_date: Option<Int48>,

    /// The time interval for this billing period.
    #[yaserde(rename = "interval")]
    pub interval: DateTimeInterval,

    /// The date / time of the last update of this resource.
    #[yaserde(rename = "statusTimeStamp")]
    pub status_time_stamp: Option<TimeType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl PartialOrd for BillingPeriod {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for BillingPeriod {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        // Primary Key - customerName (ascending)
        match self.interval.start.cmp(&other.interval.start).reverse() {
            core::cmp::Ordering::Equal => {}
            ord => return ord,
        }
        // Secondary Key - mRID (descending)
        self.href.cmp(&other.href)
    }
}

impl Validate for BillingPeriod {}

#[derive(
    Default,
    PartialEq,
    Eq,
    Debug,
    Clone,
    YaSerialize,
    YaDeserialize,
    SESubscribableList,
    SEList,
    SESubscribableResource,
    SEResource,
)]
#[yaserde(rename = "BillingPeriodList")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct BillingPeriodList {
    #[yaserde(rename = "BillingPeriod")]
    pub billing_period: Vec<BillingPeriod>,

    /// The number specifying "all" of the items in the list. Required on GET,
    /// ignored otherwise.
    #[yaserde(attribute, rename = "all")]
    pub all: Uint32,

    /// Indicates the number of items in this page of results.
    #[yaserde(attribute, rename = "results")]
    pub results: Uint32,

    /// Indicates whether or not subscriptions are supported for this resource,
    /// and whether or not conditional (thresholds) are supported. If not
    /// specified, is "not subscribable" (0).
    #[yaserde(attribute, rename = "subscribable")]
    pub subscribable: Option<SubscribableType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl Validate for BillingPeriodList {}

#[derive(
    Default,
    PartialEq,
    Eq,
    Debug,
    Clone,
    YaSerialize,
    YaDeserialize,
    SEMeterReadingBase,
    SEIdentifiedObject,
    SEResource,
    SEBillingMeterReadingBase,
)]
#[yaserde(rename = "BillingMeterReadingBase")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct BillingMeterReadingBase {
    #[yaserde(rename = "BillingReadingSetListLink")]
    pub billing_reading_set_list_link: Option<BillingReadingSetListLink>,

    #[yaserde(rename = "ReadingTypeLink")]
    pub reading_type_link: Option<ReadingTypeLink>,

    /// The global identifier of the object.
    #[yaserde(rename = "mRID")]
    pub mrid: MRIDType,

    /// The description is a human readable text describing or naming the object.
    #[yaserde(rename = "description")]
    pub description: Option<String32>,

    /// Contains the version number of the object. See the type definition for
    /// details.
    #[yaserde(rename = "version")]
    pub version: Option<VersionType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl Validate for BillingMeterReadingBase {}

#[derive(
    Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize, SEReadingBase, SEResource,
)]
#[yaserde(rename = "BillingReading")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct BillingReading {
    #[yaserde(rename = "Charge")]
    pub charge: Vec<Charge>,

    /// Indicates the consumption block related to the reading. REQUIRED if
    /// ReadingType numberOfConsumptionBlocks is non-zero. If not specified, is
    /// assumed to be "0 - N/A".
    #[yaserde(rename = "consumptionBlock")]
    pub consumption_block: Option<ConsumptionBlockType>,

    /// List of codes indicating the quality of the reading, using specification:
    /// Bit 0 - valid: data that has gone through all required validation checks
    /// and either passed them all or has been verified
    /// Bit 1 - manually edited: Replaced or approved by a human
    /// Bit 2 - estimated using reference day: data value was replaced by a
    /// machine computed value based on analysis of historical data using the
    /// same type of measurement.
    /// Bit 3 - estimated using linear interpolation: data value was computed
    /// using linear interpolation based on the readings before and after it
    /// Bit 4 - questionable: data that has failed one or more checks
    /// Bit 5 - derived: data that has been calculated (using logic or
    /// mathematical operations), not necessarily measured directly
    /// Bit 6 - projected (forecast): data that has been calculated as a
    // Projection or forecast of future readings
    #[yaserde(rename = "qualityFlags")]
    pub quality_flags: Option<QualityFlags>,

    /// The time interval associated with the reading. If not specified, then
    /// defaults to the intervalLength specified in the associated ReadingType.
    #[yaserde(rename = "timePeriod")]
    pub time_period: Option<DateTimeInterval>,

    /// Indicates the time of use tier related to the reading. REQUIRED if
    /// ReadingType numberOfTouTiers is non-zero. If not specified, is assumed to
    /// be "0 - N/A".
    #[yaserde(rename = "touTier")]
    pub tou_tier: Option<TOUType>,

    /// Value in units specified by ReadingType
    #[yaserde(rename = "value")]
    pub value: Option<Int48>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl PartialOrd for BillingReading {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for BillingReading {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        // Primary Key - timePeriod.start (ascending)
        if let Some((self_start, other_start)) =
            self.time_period.as_ref().zip(other.time_period.as_ref())
        {
            match self_start.start.cmp(&other_start.start) {
                std::cmp::Ordering::Equal => {}
                ord => return ord,
            }
        }
        // Secondary Key - consumptionBlock (ascending)
        match self.consumption_block.cmp(&other.consumption_block) {
            core::cmp::Ordering::Equal => {}
            ord => return ord,
        }
        // Tertiary Key - touTier (ascending)
        self.tou_tier.cmp(&other.tou_tier)
    }
}

impl Validate for BillingReading {}

#[derive(Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize, SEList, SEResource)]
#[yaserde(rename = "BillingReadingList")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct BillingReadingList {
    #[yaserde(rename = "BillingReading")]
    pub billing_reading: Vec<BillingReading>,

    /// The number specifying "all" of the items in the list. Required on a
    /// response to a GET, ignored otherwise.
    #[yaserde(attribute, rename = "all")]
    pub all: Uint32,

    /// Indicates the number of items in this page of results.
    #[yaserde(attribute, rename = "results")]
    pub results: Uint32,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl Validate for BillingReadingList {}

#[derive(
    Default,
    PartialEq,
    Eq,
    Debug,
    Clone,
    YaSerialize,
    YaDeserialize,
    SEReadingSetBase,
    SEIdentifiedObject,
    SEResource,
)]
#[yaserde(rename = "BillingReadingSet")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct BillingReadingSet {
    #[yaserde(rename = "BillingReadingListLink")]
    pub billing_reading_list_link: Option<BillingReadingListLink>,

    /// Specifies the time range during which the contained readings were taken.
    #[yaserde(rename = "timePeriod")]
    pub time_period: DateTimeInterval,

    /// The global identifier of the object.
    #[yaserde(rename = "mRID")]
    pub mrid: MRIDType,

    /// The description is a human readable text describing or naming the object.
    #[yaserde(rename = "description")]
    pub description: Option<String32>,

    /// Contains the version number of the object. See the type definition for
    /// details.
    #[yaserde(rename = "version")]
    pub version: Option<VersionType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl PartialOrd for BillingReadingSet {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for BillingReadingSet {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        // Primary Key - timePeriod.start (descending)
        match self
            .time_period
            .start
            .cmp(&other.time_period.start)
            .reverse()
        {
            core::cmp::Ordering::Equal => {}
            ord => return ord,
        }
        // Secondary Key - mRID (descending)
        self.mrid.cmp(&other.mrid).reverse()
    }
}

impl Validate for BillingReadingSet {}

#[derive(
    Default,
    PartialEq,
    Eq,
    Debug,
    Clone,
    YaSerialize,
    YaDeserialize,
    SESubscribableList,
    SEList,
    SESubscribableResource,
    SEResource,
)]
#[yaserde(rename = "BillingReadingSetList")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct BillingReadingSetList {
    #[yaserde(rename = "BillingReadingSet")]
    pub billing_reading_set: Vec<BillingReadingSet>,

    /// The number specifying "all" of the items in the list. Required on GET,
    /// ignored otherwise.
    #[yaserde(attribute, rename = "all")]
    pub all: Uint32,

    /// Indicates the number of items in this page of results.
    #[yaserde(attribute, rename = "results")]
    pub results: Uint32,

    /// Indicates whether or not subscriptions are supported for this resource,
    /// and whether or not conditional (thresholds) are supported. If not
    /// specified, is "not subscribable" (0).
    #[yaserde(attribute, rename = "subscribable")]
    pub subscribable: Option<SubscribableType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl Validate for BillingReadingSetList {}

/// Charges contain charges on a customer bill. These could be items like taxes,
/// levies, surcharges, rebates, or others. This is meant to allow the HAN device
/// to retrieve enough information to be able to reconstruct an estimate of what
/// the total bill would look like.
// Providers can provide line item billing, including multiple charge kinds
/// (e.g. taxes, surcharges) at whatever granularity desired, using as many
/// Charges as desired during a billing period. There can also be any number of
/// Charges associated with different ReadingTypes to distinguish between TOU
/// tiers, consumption blocks, or demand charges.
#[derive(Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize)]
#[yaserde(rename = "Charge")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct Charge {
    /// A description of the charge.
    #[yaserde(rename = "description")]
    pub description: Option<String20>,

    /// The type (kind) of charge.
    #[yaserde(rename = "kind")]
    pub kind: Option<ChargeKind>,

    /// A monetary charge.
    #[yaserde(rename = "value")]
    pub value: Int32,
}

impl Validate for Charge {}

#[derive(Default, PartialEq, Eq, Debug, Clone, Copy, YaSerialize, YaDeserialize)]
#[yaserde(rename = "ChargeKind")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
#[repr(u8)]
pub enum ChargeKind {
    #[default]
    ConsumptionCharge = 0,
    Rebate = 1,
    AuxiliaryCharge = 2,
    DemandCharge = 3,
    TaxCharge = 4,
    // 5-255 NOT RESERVED
}

impl Validate for ChargeKind {}

#[derive(
    Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize, SEIdentifiedObject, SEResource,
)]
#[yaserde(rename = "CustomerAccount")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct CustomerAccount {
    /// The ISO 4217 code indicating the currency applicable to the bill amounts
    /// in the summary. See list at
    /// <http://www.unece.org/cefact/recommendations/rec09/rec09_ecetrd203.pdf>
    #[yaserde(rename = "currency")]
    pub currency: Uint16,

    /// The account number for the customer (if applicable).
    #[yaserde(rename = "customerAccount")]
    pub customer_account: Option<String42>,

    #[yaserde(rename = "CustomerAgreementListLink")]
    pub customer_agreement_list_link: Option<CustomerAgreementListLink>,

    /// The name of the customer.
    #[yaserde(rename = "customerName")]
    pub customer_name: Option<String42>,

    /// Indicates the power of ten multiplier for the prices in this function
    /// set.
    #[yaserde(rename = "pricePowerOfTenMultiplier")]
    pub price_power_of_ten_multiplier: PowerOfTenMultiplierType,

    #[yaserde(rename = "ServiceSupplierLink")]
    pub service_supplier_link: Option<ServiceSupplierLink>,

    /// The global identifier of the object.
    #[yaserde(rename = "mRID")]
    pub mrid: MRIDType,

    /// The description is a human readable text describing or naming the object.
    #[yaserde(rename = "description")]
    pub description: Option<String32>,

    /// Contains the version number of the object. See the type definition for
    /// details.
    #[yaserde(rename = "version")]
    pub version: Option<VersionType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl PartialOrd for CustomerAccount {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for CustomerAccount {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        // Primary Key - customerName (ascending)
        match self.customer_name.cmp(&other.customer_name) {
            core::cmp::Ordering::Equal => {}
            ord => return ord,
        }
        // Secondary Key - mRID (descending)
        self.mrid.cmp(&other.mrid).reverse()
    }
}

impl Validate for CustomerAccount {}

#[derive(
    Default,
    PartialEq,
    Eq,
    Debug,
    Clone,
    YaSerialize,
    YaDeserialize,
    SESubscribableList,
    SEList,
    SESubscribableResource,
    SEResource,
)]
#[yaserde(rename = "CustomerAccountList")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct CustomerAccountList {
    #[yaserde(rename = "CustomerAccount")]
    pub customer_account: Vec<CustomerAccount>,

    /// The default polling rate for this function set (this resource and all
    /// resources below), in seconds. If not specified, a default of 900 seconds
    /// (15 minutes) is used. It is RECOMMENDED a client poll the resources of
    /// this function set every pollRate seconds.
    #[yaserde(attribute, rename = "pollRate")]
    pub poll_rate: Option<Uint32>,

    /// The number specifying "all" of the items in the list. Required on GET,
    /// ignored otherwise.
    #[yaserde(attribute, rename = "all")]
    pub all: Uint32,

    /// Indicates the number of items in this page of results.
    #[yaserde(attribute, rename = "results")]
    pub results: Uint32,

    /// Indicates whether or not subscriptions are supported for this resource,
    /// and whether or not conditional (thresholds) are supported. If not
    /// specified, is "not subscribable" (0).
    #[yaserde(attribute, rename = "subscribable")]
    pub subscribable: Option<SubscribableType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl Validate for CustomerAccountList {}

#[derive(
    Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize, SEIdentifiedObject, SEResource,
)]
#[yaserde(rename = "CustomerAgreement")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct CustomerAgreement {
    #[yaserde(rename = "ActiveBillingPeriodListLink")]
    pub active_billing_period_list_link: Option<ActiveBillingPeriodListLink>,

    #[yaserde(rename = "ActiveProjectionReadingListLink")]
    pub active_projection_reading_list_link: Option<ActiveProjectionReadingListLink>,

    #[yaserde(rename = "ActiveTargetReadingListLink")]
    pub active_target_reading_list_link: Option<ActiveTargetReadingListLink>,

    #[yaserde(rename = "BillingPeriodListLink")]
    pub billing_period_list_link: Option<BillingPeriodListLink>,

    #[yaserde(rename = "HistoricalReadingListLink")]
    pub historical_reading_list_link: Option<HistoricalReadingListLink>,

    #[yaserde(rename = "PrepaymentLink")]
    pub prepayment_link: Option<PrepaymentLink>,

    #[yaserde(rename = "ProjectionReadingListLink")]
    pub projection_reading_list_link: Option<ProjectionReadingListLink>,

    /// The account number of the service account (if applicable).
    #[yaserde(rename = "serviceAccount")]
    pub service_account: Option<String42>,

    /// The address or textual description of the service location.
    #[yaserde(rename = "serviceLocation")]
    pub service_location: Option<String42>,

    #[yaserde(rename = "TargetReadingListLink")]
    pub target_reading_list_link: Option<TargetReadingListLink>,

    #[yaserde(rename = "TariffProfileLink")]
    pub tariff_profile_link: Option<TariffProfileLink>,

    #[yaserde(rename = "UsagePointLink")]
    pub usage_point_link: Option<UsagePointLink>,

    /// The global identifier of the object.
    #[yaserde(rename = "mRID")]
    pub mrid: MRIDType,

    /// The description is a human readable text describing or naming the object.
    #[yaserde(rename = "description")]
    pub description: Option<String32>,

    /// Contains the version number of the object. See the type definition for
    /// details.
    #[yaserde(rename = "version")]
    pub version: Option<VersionType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl PartialOrd for CustomerAgreement {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for CustomerAgreement {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        // Primary Key - serviceLocation (ascending)
        match self.service_location.cmp(&other.service_location) {
            core::cmp::Ordering::Equal => {}
            ord => return ord,
        }
        // Secondary Key - mRID (descending)
        self.mrid.cmp(&other.mrid).reverse()
    }
}

impl Validate for CustomerAgreement {}

#[derive(
    Default,
    PartialEq,
    Eq,
    Debug,
    Clone,
    YaSerialize,
    YaDeserialize,
    SESubscribableList,
    SEList,
    SESubscribableResource,
    SEResource,
)]
#[yaserde(rename = "CustomerAgreementList")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct CustomerAgreementList {
    #[yaserde(rename = "CustomerAgreement")]
    pub customer_agreement: Vec<CustomerAgreement>,

    /// The number specifying "all" of the items in the list. Required on GET,
    /// ignored otherwise.
    #[yaserde(attribute, rename = "all")]
    pub all: Uint32,

    /// Indicates the number of items in this page of results.
    #[yaserde(attribute, rename = "results")]
    pub results: Uint32,

    /// Indicates whether or not subscriptions are supported for this resource,
    /// and whether or not conditional (thresholds) are supported. If not
    /// specified, is "not subscribable" (0).
    #[yaserde(attribute, rename = "subscribable")]
    pub subscribable: Option<SubscribableType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl Validate for CustomerAgreementList {}

#[derive(
    Default,
    PartialEq,
    Eq,
    Debug,
    Clone,
    YaSerialize,
    YaDeserialize,
    SEBillingMeterReadingBase,
    SEMeterReadingBase,
    SEIdentifiedObject,
    SEResource,
)]
#[yaserde(rename = "HistoricalReading")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct HistoricalReading {
    #[yaserde(rename = "BillingReadingSetListLink")]
    pub billing_reading_set_list_link: Option<BillingReadingSetListLink>,

    #[yaserde(rename = "ReadingTypeLink")]
    pub reading_type_link: Option<ReadingTypeLink>,

    /// The global identifier of the object.
    #[yaserde(rename = "mRID")]
    pub mrid: MRIDType,

    /// The description is a human readable text describing or naming the object.
    #[yaserde(rename = "description")]
    pub description: Option<String32>,

    /// Contains the version number of the object. See the type definition for
    /// details.
    #[yaserde(rename = "version")]
    pub version: Option<VersionType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl PartialOrd for HistoricalReading {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for HistoricalReading {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        // Primary Key - description (ascending)
        match self.description.cmp(&other.description) {
            core::cmp::Ordering::Equal => {}
            ord => return ord,
        }
        // Secondary Key - mRID (descending)
        self.mrid.cmp(&other.mrid).reverse()
    }
}

impl Validate for HistoricalReading {}

#[derive(Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize, SEList, SEResource)]
#[yaserde(rename = "HistoricalReadingList")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct HistoricalReadingList {
    #[yaserde(rename = "HistoricalReading")]
    pub historical_reading: Vec<HistoricalReading>,

    /// The number specifying "all" of the items in the list. Required on a
    /// response to a GET, ignored otherwise.
    #[yaserde(attribute, rename = "all")]
    pub all: Uint32,

    /// Indicates the number of items in this page of results.
    #[yaserde(attribute, rename = "results")]
    pub results: Uint32,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl Validate for HistoricalReadingList {}

#[derive(
    Default,
    PartialEq,
    Eq,
    Debug,
    Clone,
    YaSerialize,
    YaDeserialize,
    SEBillingMeterReadingBase,
    SEMeterReadingBase,
    SEIdentifiedObject,
    SEResource,
)]
#[yaserde(rename = "ProjectionReading")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct ProjectionReading {
    #[yaserde(rename = "BillingReadingSetListLink")]
    pub billing_reading_set_list_link: Option<BillingReadingSetListLink>,

    #[yaserde(rename = "ReadingTypeLink")]
    pub reading_type_link: Option<ReadingTypeLink>,

    /// The global identifier of the object.
    #[yaserde(rename = "mRID")]
    pub mrid: MRIDType,

    /// The description is a human readable text describing or naming the object.
    #[yaserde(rename = "description")]
    pub description: Option<String32>,

    /// Contains the version number of the object. See the type definition for
    /// details.
    #[yaserde(rename = "version")]
    pub version: Option<VersionType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl PartialOrd for ProjectionReading {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for ProjectionReading {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        // Primary Key - description (ascending)
        match self.description.cmp(&other.description) {
            core::cmp::Ordering::Equal => {}
            ord => return ord,
        }
        // Secondary Key - mRID (descending)
        self.mrid.cmp(&other.mrid).reverse()
    }
}

impl Validate for ProjectionReading {}

#[derive(Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize, SEList, SEResource)]
#[yaserde(rename = "ProjectionReadingList")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct ProjectionReadingList {
    #[yaserde(rename = "ProjectionReading")]
    pub projection_reading: Vec<ProjectionReading>,

    /// The number specifying "all" of the items in the list. Required on a
    /// response to a GET, ignored otherwise.
    #[yaserde(attribute, rename = "all")]
    pub all: Uint32,

    /// Indicates the number of items in this page of results.
    #[yaserde(attribute, rename = "results")]
    pub results: Uint32,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl Validate for ProjectionReadingList {}

#[derive(
    Default,
    PartialEq,
    Eq,
    Debug,
    Clone,
    YaSerialize,
    YaDeserialize,
    SEBillingMeterReadingBase,
    SEMeterReadingBase,
    SEIdentifiedObject,
    SEResource,
)]
#[yaserde(rename = "TargetReading")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct TargetReading {
    #[yaserde(rename = "BillingReadingSetListLink")]
    pub billing_reading_set_list_link: Option<BillingReadingSetListLink>,

    #[yaserde(rename = "ReadingTypeLink")]
    pub reading_type_link: Option<ReadingTypeLink>,

    /// The global identifier of the object.
    #[yaserde(rename = "mRID")]
    pub mrid: MRIDType,

    /// The description is a human readable text describing or naming the object.
    #[yaserde(rename = "description")]
    pub description: Option<String32>,

    /// Contains the version number of the object. See the type definition for
    /// details.
    #[yaserde(rename = "version")]
    pub version: Option<VersionType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl PartialOrd for TargetReading {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for TargetReading {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        // Primary Key - description (ascending)
        match self.description.cmp(&other.description) {
            core::cmp::Ordering::Equal => {}
            ord => return ord,
        }
        // Secondary Key - mRID (descending)
        self.mrid.cmp(&other.mrid).reverse()
    }
}

impl Validate for TargetReading {}

#[derive(Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize, SEList, SEResource)]
#[yaserde(rename = "TargetReadingList")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct TargetReadingList {
    #[yaserde(rename = "TargetReading")]
    pub target_reading: Vec<TargetReading>,

    /// The number specifying "all" of the items in the list. Required on a
    /// response to a GET, ignored otherwise.
    #[yaserde(attribute, rename = "all")]
    pub all: Uint32,

    /// Indicates the number of items in this page of results.
    #[yaserde(attribute, rename = "results")]
    pub results: Uint32,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl Validate for TargetReadingList {}

#[derive(
    Default,
    PartialEq,
    PartialOrd,
    Eq,
    Ord,
    Debug,
    Clone,
    YaSerialize,
    YaDeserialize,
    SEIdentifiedObject,
    SEResource,
)]
#[yaserde(rename = "ServiceSupplier")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct ServiceSupplier {
    /// E-mail address for this service supplier.
    #[yaserde(rename = "email")]
    pub email: Option<String32>,

    /// Human-readable phone number for this service supplier.
    #[yaserde(rename = "phone")]
    pub phone: Option<String20>,

    /// Contains the IANA PEN for the commodity provider.
    #[yaserde(rename = "providerID")]
    pub provider_id: Option<Uint32>,

    /// Website URI address for this service supplier.
    #[yaserde(rename = "web")]
    pub web: Option<String42>,

    /// The global identifier of the object.
    #[yaserde(rename = "mRID")]
    pub mrid: MRIDType,

    /// The description is a human readable text describing or naming the object.
    #[yaserde(rename = "description")]
    pub description: Option<String32>,

    /// Contains the version number of the object. See the type definition for
    /// details.
    #[yaserde(rename = "version")]
    pub version: Option<VersionType>,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl Validate for ServiceSupplier {}

#[derive(Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize, SEList, SEResource)]
#[yaserde(rename = "ServiceSupplierList")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct ServiceSupplierList {
    #[yaserde(rename = "ServiceSupplier")]
    pub service_supplier: Vec<ServiceSupplier>,

    /// The number specifying "all" of the items in the list. Required on a
    /// response to a GET, ignored otherwise.
    #[yaserde(attribute, rename = "all")]
    pub all: Uint32,

    /// Indicates the number of items in this page of results.
    #[yaserde(attribute, rename = "results")]
    pub results: Uint32,

    /// A reference to the resource address (URI). Required in a response to a
    /// GET, ignored otherwise.
    #[yaserde(attribute, rename = "href")]
    pub href: Option<String>,
}

impl Validate for ServiceSupplierList {}